<?php
$let=array(
"a","b","c","d","e","f","g","h","i",
"j","k","l","m","n","o","p","q","r",
"s","t","u","v","w","x","y","z"
);
//Set a counter to 1
$count = 1;
/* What is a perfect score? Usually 100. */
$psco=100;
/* Deduction for each wrong answer. May be the perfect score divided by the number of questions
i.e. 100/10=10. If you "weight" wrong answers, it could be higher. */
$wrans=10;
/* Deduction for each un answered. Usually the perfect score divided by the number of questions. */
$noans=15;
/* Change "numqsts" below to be equal to the number of questions you have on this test. (This demo
has 10 questions) */
$numqsts=10;
/* change "numqstch" below to be equal to the number of choices for each question. This script has 4
choices per question. Each question must have the same number of choices. */
$numqstch=4;
/* The questions. Be sure that the "numqsts" just above is changed to reflect the actual number of
questions you have prepared. NOTE: do not use any double quote signs in your questions. If you
need them, use the HTML " instead. Or, single quote signs may be safely used. */
$ques= array();
/* I am using a string with a delimeter to serve as the data that is read into the question array. */
$questions="Your first name is?>Your favorite colour is?>You were born in?>
Your sister's name is?>Your last name is?>Your eyes are?>You live in?>
You would like to go to?>You want to be a(n)?>You dislike?";
$ques=explode(">",$questions);
/* The letter equivalent for each correct answer (a, b, c, or d for a four answer per question format)
is entered into the correct answer array. */
$correctch="b,d,a,c,a,c,b,a,d,c";
$correct=explode(",",$correctch);
/* The possible answer choices for each question is placed into the question choies array. This test has
four possible answer choices per question. If you want five answers per question, change the variable $numqstch
above to 5 and write the appropriate number of answers below.
NOTE: do not use any double quote signs in your answers. Instead, use the HTML " or single quotes. */
$choices= array($tolalnumchs);
$qstchoices="June #1>Medea #1*>Maria #1>Liz #1
-Yellow #2>Black #2>Red #2>Purple #2*
-Canada #3*>France #3>Spain #3>Australia #3
-Alicia #4>Darcy #4>Wendy #4*>Willow #4
-Malfoy #5*>Longbottom #5>Snape #5>Zabini #5
-Green #6>Blue #6>Brown #6*>Black #6
-Sydney #7>Cape Cod #7*>Los Angeles #7>Miami #7
-Japan #8*>Russia #8>Cuba #8>Bolivia #8
-Surgeon #9>Astronaut #9>Lawyer #9>Race Car Driver #9*
-Chocolate #10>Icecream #10>Eggplant #10*>Black Cherries #10";
if(!$submit){ // if the submit button on the form is NOT pressed, print the form
/* place answer choices for each question into the choices array as a group */
$choices=explode(">",$qstchoices);
?>
<form method="post" action="quizz.php">
<?
for ($r=0; $r < $numqsts; $r++) {
/* separate the grouped answer choices into separate choices for each question */
$choicesqst=explode(">",$choices[$r]);
print $ques[$r]."<p> \n";
for ($i=0; $i < $numqstch; $i++) {
printf ("<input type=radio name=answer[%s] value=%s>%s<br> \n", $r, $let[$i] ,$choicesqst[$i]);
if($i == ($numqstch-1)){
print "<p> \n";
}
}
}
?>
<input type="submit" name="submit" value="submit">
</form>
<?
}
if($submit){ // if the submit button IS pressed, then score the quizz
$score= $psco;
//echo "\n Perfect score ".$score."<p>";
for ($t=0; $t < $numqsts; $t++) {
if (($answer[$t] !='') && ($answer[$t] != $correct[$t])){ // if incorrect answer take off points
$score = $score-$wrans;
}
if($answer[$t] ==''){ //if question not answered take off points
$score = $score-$noans;
}
}
echo "\n <p>Actual score ".$score;
}
?>
This is a php script that I got from somewhere. I need this script for my website. But it needs some modifications. When the person finishes the quiz they need to be directed to a page that is sortof like a highscore list, which needs to take their names and will record their score and name to the high score list...
If anyone has some time and wants to help? Please.....?