Jump to content

[SOLVED] PHP Quiz Issue...


Alecdude

Recommended Posts

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

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.