Simple Quiz
In this example we will build a simple quiz , this will be based around a question and then 3 options to choose from . After this we will capture the results and display a relevant message on the screen . This will be the beginning of a more advanced quiz .
Firstly the code for the quiz form , in this example we have called this page simplequiz.htm .
<html>
<head></head>
<body>
<form action="simplequiz.php" method="post">
Which of the following is true about PHP ?
<br>
<input type ="radio" name = "question" value = "answer1">
It is open source
<br>
<input type ="radio" name = "question" value = "answer2">
It is shareware
<br>
<input type ="radio" name = "question" value = "answer3">
it is a commercial product
<br>
<input type ="submit" value="submit answer">
</form>
</body>
<html>
Now here is the code for simplequiz.php which processes the answer.
<?php
//if user selects answer 1 display a well done message
if ($question == "answer1")
{
echo ("Well done that is the correct answer");
}
//otherwise display a incorrect message
else
{
echo ("Sorry that is not the correct answer");
}
?>
You can try out this example by visiting the link below
simplequiz.htm