PHP newbie here!! I'm trying to write a quiz script, below is my quiz.html form and my results.php page. What i'd like to try and figure out is how to pass the score on - say for example after the results were given for these questions, there would be a link to take you to the next chapter of the quiz on a new page and when those questions were answered the score would show combined with the score from the first set of questions. Any help would be greatly appreciated. Thanks.
Code: Select all
<html>
<head>
<title>Take the Capitals Quiz</title>
</head>
<body>
<h1>Take the Capitals Quiz</h1>
<form action="resultsexpo.php" method="post">
<br>
<input type="text" name="name"> Enter your name here
<br>
<br>
<b>What is the capital of Greece?</b>
<br>
<input type="radio" name="q1" value="Berlin"> Berlin
<input type="radio" name="q1" value="Bonn"> Bonn
<input type="radio" name="q1" value="Sparta"> Sparta
<input type="radio" name="q1" value="Athens"> Athens
<br>
<b>What is the Capital of Spain?</b>
<br>
<input type="radio" name="q2" value="Barcelona"> Barcelona
<input type="radio" name="q2" value="Madrid"> Madrid
<input type="radio" name="q2" value="Seville"> Seville
<input type="radio" name="q2" value="Accrington Stanley"> Accrington Stanley
<br>
<b>What is the Capital of France?</b>
<br>
<input type="radio" name="q3" value="La Rochelle"> La Rochelle
<input type="radio" name="q3" value="Lille"> Lille
<input type="radio" name="q3" value="Avignon"> Avignon
<input type="radio" name="q3" value="Paris"> Paris
<br>
<input type="submit" value="Check Answers">
</form>
</body>
</html>Code: Select all
<?php
$score = 0;
if ($_POST['q1'] == 'Athens')
$score++;
if ($_POST['q2'] == 'Madrid')
$score++;
if ($_POST['q3'] == 'Paris')
$score++;
?>
<html>
<head>
<style type="text/css">
.right {color:red;}
</style>
<title>Your Results for the Capitals Quiz</title>
</head>
<body>
<h1>Your Results for the Capitals Quiz <?php echo $_POST["name"]; ?></h1>
<p>For Question one you said the answer is <?php echo $_POST["q1"]; ?>. This is <?php if ($_POST["q1"] =='Athens') echo "<span class=\"right\">correct</span>"; else echo "wrong
, the correct answer is Athens"; ?>
<p>For Question two you said the answer is <?php echo $_POST["q2"]; ?>. This is <?php if ($_POST["q2"] =='Madrid') echo "<span class=\"right\">correct</span>"; else echo "wrong, the correct answer is Madrid"; ?>
<p>For Question three you said the answer is <?php echo $_POST["q3"]; ?>. This is <?php if ($_POST["q3"] =='Paris') echo "<span class=\"right\">correct</span>"; else echo "wrong, the correct answer is Paris"; ?>
<br>
<h1>Your Results for the Capitals Quiz!</h1>
<?php
$nombre = ($_POST["name"]);
echo '<b>Your capitals score was ' . $score . '/3</b><br><br>';
if ($score < 1)
echo 'You got them all wrong ' . $nombre;
else if ($score == 3)
echo 'Congratulations, a perfect score ' . $nombre;
else
echo 'An Average Score' . $nombre;
?>
</body>
</html>