Jump to content

simple php quiz script need help


jesi

Recommended Posts

i am now trying to build a simple php quiz but i couldn't figure out wt the wrong happen can somebody pls check this out
[code=php:0]
<?php
$question1 = "<b>Question 1: What does PHP stands for? </b><br />
<input type='checkbox' name='q1a' value='a'>Personal Home Page<br />
<input type='checkbox' name='q1a' value='b'>PHP Hypertext PreProcessor<br />
<input type='checkbox' name='q1a' value='c'>Private House Page<br />
<input type='checkbox' name='q1a' value='d'>None of the above<br />";
$question1_answer = "b";
$question2 = "<b>Question 2: Which one is the PHP ending tag?</b><br />
<input type='checkbox' name='q2a' value='a'>?&gt<br />
<input type='checkbox' name='q2a' value='b'>&lt;/php&gt;</br>
<input type='checkbox' name='q2a' value='c'> We don't end php<br />
<input type='checkbox' name='q2a' value='d'> None<br />";
$question2_answer = "b";
$question3 = "<b>Question 3: How can you write \"Hello World\" in php?>/b><br />
<input type='radio' name='q3a' value='a'>write(\"hello world\")<br />
<input type='radio' name='q3a' value='b'>document.echo('hello world')<br />
<input type='radio' name='q3a' value='c'>echo(\"Hello World\");<br />
<input type='radio' name='q3a' value='d'>I don't know<br />";
$question3_answer = "c";
$error = "you should select at least one answer";
?>
<html>
<head>
<title>
</title>
</head>
<body>
<?php
switch($_POST["question"]) {
case "1":
echo "<form method='POST' action='quiz.php?question=2'>
$question1
</form>";
break;
case "2":
if($_POST["q1a"]) {
if($question1_answer == $_POST['q1a']) {
$_GET[score]++;
}
echo "<form method='POST' action='quiz.php?question=3&score=$_GET[score]'>
$question2
</form>";
} else {
echo $error. "<form method='post' action='quiz.php?question=2'>
$question1
</form>";
}
break;
case "3":
if($_POST["q2a"]) {
if($question2_answer == $_POST["q2a"]) {
$_GET["score"]++;
}
echo "<form method='POST' action='quiz.php?question=4&score=$_GET[score]'>
$question3
</form>";
} else {
echo $error. "<form method='POST' action='quiz.php?question=3'>
$question2
</form>";
}
break;
case "4":
if ($_POST["q3a"]) {
if($question3_answer == $_POST["q3a"]) {
$_GET["score"]++;
}
echo "Thank you for playing this short quiz <br /> Your totol score was ".$score."<br />
<a href='quiz.php'>click here to play again<'/a>";
} else {
echo $error."<form method='POST' action='quiz.php?question=4'>
$question3
</from>";
}
break;
default:
echo "welcome to simple php quiz <br /> <a href='quiz.php?question=1'>click here to begin</a>";
}
?>
</body>
</html>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/29326-simple-php-quiz-script-need-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.