I need help on this quiz page iam doing, it doesnt work correctly, the only problem with it is that the score doesnt work correctly, i need the score to incremenet by 1 everytime the user gets a right answer, and what actually happens is when i click on ANY choice the incremenets score by 1 even if it is wrong.
Also, it starts off with score = 1 anyway i dont know why it does this, it should be set to zero wen it loads up ............obvisouly.
Any help would be greatly appreciated because this is the last thing i need to do for my coursework and iam STUMPED i dont know what to do here
Thanks, and i will give 10 points to the best answer.
$quiz = mysql_query("SELECT * FROM question LIMIT 28");
$quizResult = mysql_fetch_assoc($quiz);
while($row = mysql_fetch_assoc($quiz))
{
echo "</br>";
echo str_replace("`","", $row['question']);
echo "</br>";
echo "<input name='$row[questionId]' type='radio' value='$row[answer]' />" . $row['answer'];
echo "</br>";
$resource = mysql_query("SELECT * FROM incorrect WHERE questionID = '$row[questionId]'");
while ($line = mysql_fetch_array($resource))
{
$current = $line['Incorrect Answer'];
echo "</br>";
echo " <input name='$row[questionId]' type='radio' value='$current' />" . $line['Incorrect Answer'];
echo "</br>";
}
}
$score = 0;
foreach ($_POST as $key)
{
$sql2 = ("SELECT answer FROM question WHERE questionId = '$key'");
$resource2 = mysql_query($sql2,$conn);
$cAnswer = mysql_fetch_array($resource2);
strip_tags($cAnswer['answer']) . "<br />";
strip_tags($_POST[$key]) . "*<br />";
if (strip_tags($cAnswer['answer']) == strip_tags($_POST[$key]))
{
$score++;
}
}
echo ("<br /><h2><strong><font color='#0006F'>You scored: $score out of a possible: 28 </h2></strong></font></br>");
$sqlScore= "UPDATE user SET NetScore = '$score' WHERE UserName = '$_SESSION[username]'";
mysql_query ($sqlScore,$conn);
$score = $score / 28 * 100;
echo ("Your percentages is: " . round($score) );
if ($score < 45)
{
echo ("<h2><strong><font color='#FF0000'></br>You failed the quiz! </h2></strong></font");
}
else
{
echo ("<h2><strong><font color='#006600'></br>You passed the quiz! </h2></strong></font");
}
Also, it starts off with score = 1 anyway i dont know why it does this, it should be set to zero wen it loads up ............obvisouly.
Any help would be greatly appreciated because this is the last thing i need to do for my coursework and iam STUMPED i dont know what to do here
Thanks, and i will give 10 points to the best answer.
$quiz = mysql_query("SELECT * FROM question LIMIT 28");
$quizResult = mysql_fetch_assoc($quiz);
while($row = mysql_fetch_assoc($quiz))
{
echo "</br>";
echo str_replace("`","", $row['question']);
echo "</br>";
echo "<input name='$row[questionId]' type='radio' value='$row[answer]' />" . $row['answer'];
echo "</br>";
$resource = mysql_query("SELECT * FROM incorrect WHERE questionID = '$row[questionId]'");
while ($line = mysql_fetch_array($resource))
{
$current = $line['Incorrect Answer'];
echo "</br>";
echo " <input name='$row[questionId]' type='radio' value='$current' />" . $line['Incorrect Answer'];
echo "</br>";
}
}
$score = 0;
foreach ($_POST as $key)
{
$sql2 = ("SELECT answer FROM question WHERE questionId = '$key'");
$resource2 = mysql_query($sql2,$conn);
$cAnswer = mysql_fetch_array($resource2);
strip_tags($cAnswer['answer']) . "<br />";
strip_tags($_POST[$key]) . "*<br />";
if (strip_tags($cAnswer['answer']) == strip_tags($_POST[$key]))
{
$score++;
}
}
echo ("<br /><h2><strong><font color='#0006F'>You scored: $score out of a possible: 28 </h2></strong></font></br>");
$sqlScore= "UPDATE user SET NetScore = '$score' WHERE UserName = '$_SESSION[username]'";
mysql_query ($sqlScore,$conn);
$score = $score / 28 * 100;
echo ("Your percentages is: " . round($score) );
if ($score < 45)
{
echo ("<h2><strong><font color='#FF0000'></br>You failed the quiz! </h2></strong></font");
}
else
{
echo ("<h2><strong><font color='#006600'></br>You passed the quiz! </h2></strong></font");
}