Jump to content

Help with simple PHP quiz


Spray62

Recommended Posts

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 by Spray62
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.