Scoring Quizzes with Globals Off

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ucichem
Forum Newbie
Posts: 8
Joined: Tue Jul 25, 2006 1:08 pm

Scoring Quizzes with Globals Off

Post 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.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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
ucichem
Forum Newbie
Posts: 8
Joined: Tue Jul 25, 2006 1:08 pm

Post by ucichem »

Thanks for the help!! Taking $_POST out worked. :-)
Post Reply