Scoring Quizzes with Globals Off
Posted: Wed Aug 02, 2006 1:45 pm
I am trying to use php with a form to calculate and total up how many questions a user has answered correctly, then display that information to the user. I have found several codes online, but none work on my system because I have the Globals turned off. Can anybody tell me what i need to add or change in order to calculate scores with globals turned off?
Here is the html I am working with.
Here is the php I am working with:
Here is the html I am working with.
Code: Select all
<form action=examplephp.php method="GET">
1. PHP is a server-side scripting language.
<UL>
<INPUT TYPE="RADIO" NAME="question1" VALUE="answer1.1">True<BR>
<INPUT TYPE="RADIO" NAME="question1" VALUE="answer1.2">False<BR>
<INPUT TYPE="SUBMIT" VALUE="Done" >
</FORM>Code: Select all
<?php
$score = 0; //initialize score to zero
?>
<h4>Question 1 Feedback</h4>
PHP is a server-side scripting language.
<p><ul>Correct Answer: True<br>
Your answer was:
<?php
if ($_GET[question1] == "answer1.1")
{
echo ("<b>Correct</b>");
$score = $score + 1;
}
else
{
echo ("<b>Incorrect</b>");
}
?></ul>
<hr>
<b>Total score:</b>You answered <?php echo ($_POST[score]);?> question(s) correctly.