// Functions
function showanswer($youranswer) {
include 'questions.php';
if($youranswer == '') { $youranswer = '(No Answer Selected)';}
$rightorwrong = strtoupper ("
Incorrect");
$correctanswer = strtoupper ("
Correct!");
switch ($_POST['question']){
case "1":
if($youranswer == $q1answer) { $rightorwrong = $correctanswer; }
echo "
Your Answer: ".$youranswer;
echo '
Correct Answer is: '.$q1answer;
echo $rightorwrong;
echo '
'.$q1why;
$setquestion = '2';
setcookie("Q1", $rightorwrong);
break;
case "2":
if($youranswer == $q2answer) { $rightorwrong = $correctanswer; }
echo "
Your Answer: ".$youranswer;
echo '
Correct Answer is: '.$q2answer;
echo $rightorwrong;
echo '
'.$q2why;
$setquestion = '3';
setcookie("Q2", $rightorwrong);
break;
case "3":
if($youranswer == $q3answer) { $rightorwrong = $correctanswer; }
echo $rightorwrong;
echo "
Your Answer: ".$youranswer;
echo '
Correct Answer is: '.$q3answer;
echo '
'.$q3why;
$setquestion = '4';
setcookie("Q3", $rightorwrong);
break;
case "4":
if($youranswer == $q4answer) { $rightorwrong = $correctanswer; }
echo $rightorwrong;
echo "
Your Answer: ".$youranswer;
echo '
Correct Answer is: '.$q4answer;
echo '
'.$q4why;
$setquestion = '5';
setcookie("Q4", $rightorwrong);
break;
case "5":
if($youranswer == $q5answer) { $rightorwrong = $correctanswer; }
echo $rightorwrong;
echo "
Your Answer: ".$youranswer;
echo '
Correct Answer is: '.$q5answer;
echo '
'.$q5why;
$setquestion = '99';
setcookie("Q5", $rightorwrong);
break;
} // switch
// go to next question
echo "
";
if($setquestion == '99') {
echo '
';
} else {
echo '
Correct!";
if($_COOKIE["Q1"] == $correct) { $totalcorrect = $totalcorrect + 1; }
if($_COOKIE["Q2"] == $correct) { $totalcorrect = $totalcorrect + 1; }
if($_COOKIE["Q3"] == $correct) { $totalcorrect = $totalcorrect + 1; }
if($_COOKIE["Q4"] == $correct) { $totalcorrect = $totalcorrect + 1; }
if($_COOKIE["Q5"] == $correct) { $totalcorrect = $totalcorrect + 1; }
$score = $totalcorrect / 5 * 100;
echo "Your results:
";
echo "
Question 1: ".$_COOKIE["Q1"];
echo "
Question 2: ".$_COOKIE["Q2"];
echo "
Question 3: ".$_COOKIE["Q3"];
echo "
Question 4: ".$_COOKIE["Q4"];
echo "
Question 5: ".$_COOKIE["Q5"];
echo "
Score: ".$score."%";
echo "
Summary: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
echo '
start over';
break;
}
if($_POST['question'] != '99') {
?>
} // check for end of quiz, question = 99
} // end of showquestion ?>
// main logic
if(!isset($_POST['showanswer'])) {
if(!isset($_POST['question'])) {
$setquestion = '1';
//setcookie("user", "Your Answer", time()+3600);
}
else {
$setquestion = $_POST['question'];
}
showquestion($setquestion);
} else {
showanswer($_POST['youranswer']);
}
?>