Page 1 of 1

Scoring Quizzes with Globals Off

Posted: Wed Aug 02, 2006 1:45 pm
by ucichem
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.

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>
Here is the php I am working with:

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.

Posted: Wed Aug 02, 2006 2:13 pm
by Luke
what happens when you execute that code?

the only thing that jumps out to me is $_POST[score] should be $score since it wasn't posted...

also (in my configuration anyway) not using quotes in the index of the array will throw a notice

Posted: Mon Aug 07, 2006 12:26 pm
by ucichem
Thanks for the help!! Taking $_POST out worked. :-)