Spray62 Posted June 30, 2013 Share Posted June 30, 2013 (edited) Hi, Just to some up quickly I'm trying to create a simple two page quiz with an answer page and I'm stuck. This is just the rough code as you can see its only one question to try and get it to work before I add more questions. The aim is for the user to answer the questions on the first page then on the second page and the third page displays whether the answers were right or wrong. The code on the first page is <form name="input" action="quizpage2.php" method="post"> Username: <input type="text" name="user"> <p> In which film did Simon Pegg try and impress Thandie Newton by donning tight shorts and trainers? </p> <input type="radio" name='ans1' value="Hot Fuzz"/> Hot Fuzz<br /> <input type="radio" name='ans1' value="Good Luck Chuck"/> Good Luck Chuck<br /> <input type="radio" name='ans1' value="Run Fatboy Run"/> Run Fatboy Run<br /> <input type="submit" value="Page 2"> </form> The code on the second page is <?php session_start(); $_SESSION['ans1'] = $_POST['ans1']; ?> <form name="input" action="answers.php" method="post"> <p> What is Harry Potter? </p> <input type="radio" name='ans11' value="Wizard" /> Wizard<br /> <input type="radio" name='ans11' value="Goblin" /> Goblin <br /> <input type="radio" name='ans11' value="Troll" /> Troll<br /> <input type="submit" value="Submit"> </form> And then the answers page <?php session_start(); $_SESSION['ans1] = $_POST['ans1']; ?> <?php $ans1=$_SESSION['ans1']; if ($ans1 == "Run Fatboy Run") { echo "Correct"; } else { echo "Incorrect the answer is Run Fatboy Run"; } ?> All it shows on the answer page is "Incorrect the answer is Run Fatboy Run" even when I choose that as the answer. I'm not sure why it isn't working. Whether its the "sessions" I'm doing incorrect or using ' instead of " but I've tried everything and spent around 10 hours doing so. Much appreciated! Edited June 30, 2013 by Spray62 Quote Link to comment Share on other sites More sharing options...
Barand Posted June 30, 2013 Share Posted June 30, 2013 When you get to the answer page, $_POST['ans1'] no longer exists so you are clearing the session value. You need to store $_POST['ans11'] on that page. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.