Alecdude Posted December 16, 2008 Share Posted December 16, 2008 Hello all, I just need a little help on this. It seems to always output as 0, even if you get it right. It si a simple HTML/PHP script that takes information and compares it. Input page: <form action="results.php" method="post"> <ol> <li>This is an example of a true/false question. (Answer is false)<br> <input type="radio" value="true" name="n1">True <input type="radio" value="false" name="n1">False<br> </li> <li>This is an example of a multiple choice question. (Answer is A, for Alec) <br> <input type="radio" value="a" name="n2">A <input type="radio" value="b" name="n2">B <input type="radio" value="c" name="n2">C <input type="radio" value="d" name="n2">D<br> </li> </ol> <br><input type="submit" value="Submit Answers"> </form> And the PHP results: <?php $score=0; if ($n1=="false") { $score=$score+1; } if ($n2=="a") { $score=$score+1; } if ($score > 2) { $sql = "UPDATE users SET Money=Money+10 WHERE id=".$_SESSION['user_id'].""; $result = mysql_query($sql) or die (mysql_error()); echo "You got enough points to win the quiz, which was ".$score."! 10 ZukKen have been rewarded to your account."; } else { echo "Your score , which was ".$score."/2, was not enough to win any ZukKen."; } ?> Link to comment https://forums.phpfreaks.com/topic/137141-solved-php-quiz-issue/ Share on other sites More sharing options...
trq Posted December 16, 2008 Share Posted December 16, 2008 $nl is not defined anywhere in your code. You need to use $_POST['nl'] instead. Link to comment https://forums.phpfreaks.com/topic/137141-solved-php-quiz-issue/#findComment-716369 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.