Problem with radio buttons and PHP

Hello eveybody! I’m a beginner in PHP. I’m trying to make a fake poll using radio buttons and a script, and my code doesn’t work to the point where I’m thinking I’ve gotten something completely wrong.

I don’t need the answer to be stored anywhere, but I need the poll to refresh the page with a thank you message after a vote has been cast. Here is the code of the main page:

[PHP]<?php

if ($_POST[vote]=='1') {echo("Thank you for voting.");}
else {echo("
<p><b>QUESTION</b></p>
<p>&nbsp; </p>
<form action=\"vote.php\" method=\"post\">
  <p>
    <input type=\"radio\" name=\"vote1\" value=1 > OPTION 1<br />
    <input type=\"radio\" name=\"vote2\" value=1 > OPTION 2<br />
    <input type=\"radio\" name=\"vote3\" value=1 > OPTION 3
  </p>
  <p>&nbsp;</p>
</form>
<input type=\"submit\" value=\"VOTE\" />
</form>
");}

?> [/PHP]

and the script (vote.php):

[PHP]<?php

$vote=$_POST[vote];

header(“main.php?vote=”.$vote);

?>[/PHP]

I’ve been looking at tutorials but I still haven’t found what the problem is… The output is crazy wrong, I’m getting fields where there should have been buttons and the ");} ?> trail of the code is showing. Please help…

Hi there,

Is it possible to show the rest of the code?

Also, I’m not sure if you’ve done it on purpose but the names of your radio fields are all different - for the user to toggle their choice between the 3 they all need to have the same name and then change the values to 1,2 and 3.

In regards to the code at the end being output onto your webpage, I did not get that when I used your code locally, seeing the rest of the code may help.

Sponsor our Newsletter | Privacy Policy | Terms of Service