Jump to content

Just Starting Php


betokahn

Recommended Posts

Hi all, I saw this code of a form that uses a PHP script. It was in a book, where i am learning PHP, but it didn't worked. What i mean is that the form was ok and when i clicked the button i went to another page of the PHP file, but then there was just the messages of echo command without the variable parameters, or they were unchanging, maybe there is something wrong in the syntax? I use linux, do i need to set permissions in the files?(now they are rw for user, group and others) <html><form method=post action=processa.php>Seu Nome:<input type=text name=edNome><br><br>Vinho preferido:<input type=radio name=rgVinho value=br checked>Vinho Branco<input type=radio name=rgVinho value=mr >Merlot<input type=radio name=rgVinho value=tt >Tinto<br><br>Hora ideal para beber:<input type=checkbox name=bebi[] value=m >Manhã<input type=checkbox name=bebi[] value=a >Almoço<input type=checkbox name=bebi[] value=j >Jantar<input type=checkbox name=bebi[] value=q >A qualquer hora<br><br><input type=submit value="Click aqui"></form></html> This is in the file processa.php:<?phpswitch ($rgVinho) {case 'br': $msgVinho='Ovinho branco é bom para o coração';break;case 'tt':$msgVinho='O vinho tinto é bom para o sangue';break;default: $msgVinho='O merlot é excelente';break;} $qtsVezes = count($bebi);if ($qtsVezes <=1)$msgVezes='Você bebe moderadamente';elseif ($qtsVezes > 1 && $qtsVezes < 4 )$msgVezes='é melhor ir com calma!';else $msgVezes='Melhor você procurar um centro de AA.'; echo "Como vai $edNome?";echo "$msgVinho $msgVezes";?> Thank you

Link to comment
Share on other sites

Hi all, I saw this code of a form that uses a PHP script. It was in a book, where i am learning PHP, but it didn't worked. What i mean is that the form was ok and when i clicked the button i went to another page of the PHP file, but then there was just the messages of echo command without the variable parameters, or they were unchanging, maybe there is something wrong in the syntax? I use linux, do i need to set permissions in the files?(now they are rw for user, group and others) <html><form method=post action=processa.php>Seu Nome:<input type=text name=edNome><br><br>Vinho preferido:<input type=radio name=rgVinho value=br checked>Vinho Branco<input type=radio name=rgVinho value=mr >Merlot<input type=radio name=rgVinho value=tt >Tinto<br><br>Hora ideal para beber:<input type=checkbox name=bebi[] value=m >Manhã<input type=checkbox name=bebi[] value=a >Almoço<input type=checkbox name=bebi[] value=j >Jantar<input type=checkbox name=bebi[] value=q >A qualquer hora<br><br><input type=submit value="Click aqui"></form></html> This is in the file processa.php:<?phpswitch ($rgVinho) {case 'br': $msgVinho='Ovinho branco é bom para o coração';break;case 'tt':$msgVinho='O vinho tinto é bom para o sangue';break;default: $msgVinho='O merlot é excelente';break;} $qtsVezes = count($bebi);if ($qtsVezes <=1)$msgVezes='Você bebe moderadamente';elseif ($qtsVezes > 1 && $qtsVezes < 4 )$msgVezes='é melhor ir com calma!';else $msgVezes='Melhor você procurar um centro de AA.'; echo "Como vai $edNome?";echo "$msgVinho $msgVezes";?> Thank you
The PHP line:$qtsVezes = count($bebi);has been entered wrong. There is no variable $bebi It should be:$qtsVezes = count($_POST['bebi']); That seems to be the only error in your script. Happy scripting :)
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...