How to call php on a radio button

Asked

Viewed 120 times

1

I’m trying to call PHP to mark 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

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";
}
  • Thanks friend, speak of attention I altered and it worked vlw

Browser other questions tagged

You are not signed in. Login or sign up in order to post.