Hi i need this quiz page to register the score, and display it also. i have written code but i dont know why its not working it seems fine to me, any help would be greatly appreciated.
If there are problems with it could you please tell the correct code, thanks.
<form enctype="multipart/form-data" form id="form1" name="form1" method="post" action="networkquiz.php">
<p>
<label for="quiz"></label>
</p>
<p>
<?php
if ($_SESSION['role'] == 'student') {
$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>";
}
}
$CorrectAnswers=$row['answer'];
$Incorrect=$current;
$score = 0;
foreach($_POST as $CorrectAnswers)
{
$score+1;
}
if($answer)
{
echo "You have scored ". $score. " out of 28";
}
if($_SESSION['role'] =='student')
{
$sqlScore= "INSERT INTO user (NetScore) VALUES ('$score')WHERE StudentID = '$_SESSION[studentID]'";
mysql_query ($sqlScore);
}
}
If there are problems with it could you please tell the correct code, thanks.
<form enctype="multipart/form-data" form id="form1" name="form1" method="post" action="networkquiz.php">
<p>
<label for="quiz"></label>
</p>
<p>
<?php
if ($_SESSION['role'] == 'student') {
$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>";
}
}
$CorrectAnswers=$row['answer'];
$Incorrect=$current;
$score = 0;
foreach($_POST as $CorrectAnswers)
{
$score+1;
}
if($answer)
{
echo "You have scored ". $score. " out of 28";
}
if($_SESSION['role'] =='student')
{
$sqlScore= "INSERT INTO user (NetScore) VALUES ('$score')WHERE StudentID = '$_SESSION[studentID]'";
mysql_query ($sqlScore);
}
}