jesi Posted December 3, 2006 Share Posted December 3, 2006 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'>?><br /><input type='checkbox' name='q2a' value='b'></php></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><?phpswitch($_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 More sharing options...
trq Posted December 3, 2006 Share Posted December 3, 2006 Sorry, but what exactly isn't working?. Link to comment https://forums.phpfreaks.com/topic/29326-simple-php-quiz-script-need-help/#findComment-134438 Share on other sites More sharing options...
esukf Posted December 3, 2006 Share Posted December 3, 2006 Instead of switch($_POST["question"]), you should be using switch($_GET["question"]) since your question numbers are being passed via the querystring. Also, you are missing the submit button for your forms to go to the next question. Link to comment https://forums.phpfreaks.com/topic/29326-simple-php-quiz-script-need-help/#findComment-134464 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.