PHP/Bootstrap radio selector not working

Asked

Viewed 82 times

-4

Can you explain to me why the code below does not work? It is giving error when I run.

Displays the error below:

inserir a descrição da imagem aqui

Follow the code in the Pastebin: https://pastebin.com/6pH5AW4i

  • 1

    The variable $sexo is not initialized

  • Do you know how to fix it? I’m very Noob about it...

  • You can add one more condition in your if (!empty($sexo) && $sexo=="F" )

  • just declare the variable sex at the beginning of PHP <?php $sexo=''; ?>

  • Where does the variable sex value come from?

1 answer

0


In this case you can use the function "isset" to test if the variable exists:

<input class="form-check-input" type="radio" name="sexo" id="sexo" value="M" <?php echo isset($sexo) && $sexo == "M" ? "checked" : null; ?>/> Masculino

However, the most common thing in these cases is to disable some PHP errors so that this type of warning does not go off. For this you need to add some exceptions in your file "php.ini".

It is also possible to disable these errors by calling this Function:

error_reporting(0);
  • 1

    It worked perfectly, thank you!!

Browser other questions tagged

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