I am building a Quiz generator using PHP. The idea is to set up an array with questions and answers and let PHP build most of the required HTML (that way the same code can be reused for many different quizzes).
I am almost there >:( but have trouble with $_SESSION I think.
After the user “submits” answers, PHP gets them via $_POST and the code reloads the quiz with the answers submitted, then display a score message (this last bit not there yet. The problem is that successive “submit” displays the answer selections of the previous “submit”. This can easily be visualized by answering TRUE to all questions, submit, then FALSE to all questions and submit again. Continuing to “submit” will alternate between the set of answers. >:(
The funny thing is that the debugging echos that come to the top of the page actually have the correct answers for the current “submit”.
You can see it all at:
http://www.woodyacresranch.com/Quizzes/Quiz_Handler_FRB.php
Here is the code:
[php]<?php
// Starts the session
session_start();
$process = $_GET['process'];
// Get session variables
for ( $x=0 ; $x<=$qQty ; $x++ ) // $x walks the question sets
{
for ( $y=0 ; $y<=$sub ; $y++ ) // $y walks the question array
{
// The first element in question array is the question title
if ( $y == 0 ) {$_SESSION["a".$x.$y] = "";}
else
{
// Get the answers for question $x
$_SESSION["a".$x.$y] = trim($_POST["a".$x.$y]);
}
}
}
// Define Quiz questions and load the SESSION answers
$qSet = array(
array(
array("Conditions of Participation"), // This is the title of the question
array("Dogs do not need a tattoo or microchip to compete in French Ring Sport as long as
they are registered with a breed affiliation.","1.1.2","B","false",$_SESSION["a01"]),
array("Members are only allowed to compete with 3 Blue dogs in their lifetime.","1.1.6","B","false",$_SESSION["a02"]),
array("A female dog in heat must compete after all the other dogs in the trial.","1.1.10","B","true",$_SESSION["a03"]),
array("An individual decoying a trial is authorized to compete his or her own dog,
as long as the dog is presented by another handler.","1.1.11","B","false",$_SESSION["a04"]),
),
array(
array("The following is needed to hold a trial:"), // This is the title of the question
array("A judge and a deputy judge.","1.2.6","B","true",$_SESSION["a11"]),
array("A Ring Steward.","1.2.6","B","false",$_SESSION["a12"]),
array("A blank revolver or something that make a similar noise.","1.2.6","B","false",$_SESSION["a13"]),
array("A horn.","1.2.6.","B","true",$_SESSION["a14"]),
array("A minimum of eight cones or flags.","1.2.6","B","true",$_SESSION["a15"]),
array("A minimum of eight pieces of food for the Food Refusal exercise.","1.2.6","B","false",$_SESSION["a16"]),
),
);
?>
Quizzes <?php include("/home/content/05/8083005/html/header.html"); include("/home/content/05/8083005/html/topbar.html"); include("/home/content/05/8083005/html/sidebar.html"); ?>Handler Quiz
Please help. Thanks in advance.