Creating a PHP Quiz Page
LAB #2
PHP can be used to evaluate Quiz pages. The quiz page may be written in a
normal form fashion, either mutiple choice or True-false. After you create
this form page, setting your PHP page as the action for the form, your php
page can pick up the variables and evaluate the results of the form, scoring
the form.
Activity:
1. Create a 10 question quiz
- 5 questions should be true false
- 5 should have 3-5 answer choices.
- Each question will represent a variable
- Each variable will be set as a value for the form
- No entries will cause an error.
2. Create the PHP script that will evaluating the results of the Quiz.
The PHP script will return the number of questions right.
Answer:
Creating the HTML Form
The quiz is written in straight HTML using a form method. write it as the
following:
Creating the PHP result form
1. Open maguma editor or another PHP editor. |
|
2. Title your page in HTML. |
Mindy's Silly Beginner PHP Quiz |
3. Put in what this page represents as part of the quiz
in HTML. |
RESULTS |
4. Set up the PHP opening tag. (already in a php editor) |
(open script tag) (close script tag) |
5. Set the variable $score to 0 so that each time the
script is run, the score is reset. |
$score=0; |
6. Scoring represents testing each line to see if it is
true of not. If it is true we will reassign $score so that it is equal
to $score + 1. since Question 1 is false, I test to see if $no1 is equal
to "false" where "false" is a string.If this is true, 1 is added to the
score.
Number 2 is true, so I test to see if that is the answer they
provided. If it is, I add 1 to the score.
I go through each question like this. |
if ($no1=="false")
$score=$score+1;
if ($no2=="true")
$score=$score+1; |
|
|
7. TO use this as a learning tool, I can put in an if
else statement. If they have the right answer I can score a point, else,
I give an explanation. Go back and add your explanations as to why
their answers were wrong. |
if ($no1=="false")
$score=$score+1;
else {
echo "1. False In writing PHP, the
form which the variables are set CAN BE BUT DOES NOT HAVE TO BE
in a document with the extension of .PHP.
";
} |
8. Add your statement to display your score by using the
echo statment. Use the following:
- HTML included in a quotes to label this score
- periods to connect the statements.
|
echo "Your PHP beginner quiz score is
".$score." "; |
|
|
|