quiz does not work...


#1

Hi, i made this quiz, and it always displays that i got 20% no matter what i do, please help.
[php]

<? $q = array (2, 0, 1, 2, 2); $q1_bad = array ("a container for integers only", "name can start with a number", "can contain words, sentences, numbers"); $q2_bad = array ("a container for strings", "a mathematical approach to storing integers", '$string[x]'); $q3_bad = array ("CGI", "HTML", "PHP"); $q4_bad = array ("HTML & CGI", "PHP", "HTML & PHP"); $q5_bad = array ("sint", "intrand", "srand");

if ($action == “true”) { $right = 0;
print (“thank you for taking my quiz”);
if (answer_1 == $q[0]) { $right++; }
if (answer_2 == $q[1]) { $right++; }
if (answer_3 == $q[2]) { $right++; }
if (answer_4 == $q[3]) { $right++; }
if (answer_5 == $q[4]) { $right++; }

$percentage = ($right / 5) * 100;
print(“

You scored $percentage % on the quiz!”); exit; }
?>

Take this php quiz

Question 1: A string is ...
<? print ($q1_bad[0]) ?>
<? print ($q1_bad[1]) ?>
<? print ($q1_bad[2]) ?>

Question 2: An array is …

<? print ($q2_bad[0]); ?> <? print ($q2_bad[1]); ?> <? print ($q2_bad[2]); ?>

Question 3: Building a form primarily requires …

<? print ($q3_bad[0]); ?>

<? print ($q3_bad[1]); ?>

<? print ($q3_bad[2]); ?>

Question 4: This script is an example of …

<? print ($q4_bad[0]); ?> <? print ($q4_bad[1]); ?> <? print ($q4_bad[2]); ?>

Question 5: Before generating random numbers, you use …

<? print ($q5_bad[0]); ?>

<? print ($q5_bad[1]); ?>

<? print ($q5_bad[2]); ?>

[/php]


#2

First off you need to use superglobals and second you have no superglobal or even $ on your answer variables…

need to change

if (answer_1 == $q[0]) { $right++; } 

to

if ($_POST['answer_1'] == $q[0]) { $right++; } 

etc… for each answer and change:

if ($action == "true")

to

if (!empty($_POST['action']) && $_POST['action'] == "true") {