How to call php on a radio button

1

I'm trying to call PHP to dial a radio button but I'm not getting it.

PHP:

if($result['sx_sexo']=="Masculino")
{
    $Result_sexoM ="checked";
}
else
{
    $Result_sexoF ="checked";
}

Radio button

<p>
     <input  name="sexo" type="radio" id="rd_masculino" value="Masculino" <?php echo $Result_sexoM ?> />
     <label for="rd_masculino">Masculino</label>
     <input  name="sexo" type="radio" id="rd_feminino" value="Feminino" <?php echo $Result_sexoF ?> />
     <label for="rd_feminino">Feminino</label>
</p>

error

  

Notice: Undefined variable: Result_sexoM in

    
asked by anonymous 14.06.2018 / 20:08

1 answer

2

You have to initialize it before:

$Result_sexoM = '';
$Result_sexoF = '';

if($result['sx_sexo'] == "Masculino") {
    $Result_sexoM = "checked";
}
else {
    $Result_sexoF = "checked";
}
    
14.06.2018 / 20:10