-1
Hello, I’m having the problem in the code where my "IF" only returns the first result:
if ($aluno['janimal']="1"){
$animal = "Réptil";}
elseif($aluno['janimal']="2"){
$animal ="Cavalo";}
elseif($aluno['janimal']="3"){
$animal ="Porco";}
elseif($aluno['janimal']="4"){
$animal ="Tartaruga";}
elseif($aluno['janimal']="5"){
$animal ="Roedores(Coelho, Chinchila, hamster)";}
elseif($aluno['janimal']="6"){
$animal ="Peixes";}
elseif($aluno['janimal']="7"){
$animal ="Aves";}
elseif($aluno['janimal']="8"){
$animal ="Gato";}
elseif($aluno['janimal']="9"){
$animal ="Cão";}
elseif($aluno['janimal']="10"){
$animal ="Invertebrados";}
elseif($aluno['janimal']="11"){
$animal ="Anfibios";}
else{
$animal ="Outros";}
Is there a problem?
I call the variable "$animal" at another time....
Use two signal of
=. Thus==. When you use only one, you are stating that if the variable$aluno['janimal']receive the value of1, then,$animalis equal toRéptil. With two==you are comparing whether the value of the variable is equal to1But with that amount ofifsrecommend using theswitch...case– Valdeir Psr
When I put == it gives the following error: Notice: Undefined index: janimal in C: xampp htdocs addemp informacao.php on line 286
– Carolina Perretti Cabral
This means that the variable
$animaldoes not have the value ofjanimal. Use the functionissetto check if the value exists.if (isset($animal['janimal'])) { /* verifica os outros if's */ }– Valdeir Psr