Poddy Posted April 6, 2008 Share Posted April 6, 2008 I have a radio form that does not process correctly... i have a previous variable that has a value of 1 to 4 (using mt_rand) for generating a position of a correct answer for a quiz yet the form does not return the correct value each time... i echo the values and then click on the correct radio button and submit the form, yet only sometimes it gives me a correct answer. here is the code: <?php $values = mt_rand(1,4); $values = "a" . $values; echo "values is:" . $values; ?> <html> <body> <br> <form action="ac.php" method="POST" name="answers"> <input type="radio" name="answers" value="a1">radio1<br> <input type="radio" name="answers" value="a2">radio2<br> <input type="radio" name="answers" value="a3">radio3<br> <input type="radio" name="answers" value="a4">radio4<br> <input type="submit" name="submit"> </form> </body> </html> and the ac.php <?php if (isset($_POST['submit'])) { $radio = $_POST['answers']; echo "you selected:" . $radio; if ($values == $radio) { echo "you got the answer correct"; } else { echo "you got the answer wrong"; } } ?> Link to comment https://forums.phpfreaks.com/topic/99870-radio-form-processing/ Share on other sites More sharing options...
hitman6003 Posted April 6, 2008 Share Posted April 6, 2008 Variables are not persistent between page loads. In other words, after the page is sent to the browser, all variables are destroyed, losing their value. You must put the value of "$values" from the first script either in a session variable or in a hidden form field and retrieve it in the second script. Link to comment https://forums.phpfreaks.com/topic/99870-radio-form-processing/#findComment-510746 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.