Basically I'm making an Assessment and feedback system, which allows instructors to create tests and feedback for each answer, which are then taken by students. Now I've got the whole system working, the instructor sub system consists of forms to create questions and feedback all of which are then stored in a backend MySQL database. And the learner subsystem basically deals with displaying tests and grading the answers given by the student. And this is where my problem is.
In order to mark the students response to the multiple-choice questions, each answer has a true or false value related to it. So If the student gets an answer correct the variable $score is incremented by 1. Now score is passed from a hidden text box on page show_test.php to page show_feedback.php where this calculation is carried out and $score echoed (code shown below:) however the score is not being echoed.
Any ideas?
Regards,
Simon.
Code: Select all
<?php
$answerno = $_POST['answer'];
$question = $_POST['questionno'];
$testno = $_POST['testno'];
$scores = $_POST['score'];
#connect to database
$conn = @mysql_connect( "****", "****", "****" )
or die( "could not connect" );
#select the specified database
$rs = @mysql_select_db ( "db_sn202", $conn )
or die( "could not select database" );
#create the sql query
//since there is no feedback 1, must change 1 to blank
$newno = ($answerno == 1 ? '' : $answerno);
$sql = "SELECT `feedback".$newno."` FROM `question` WHERE `testno` = '".$testno."' AND `questionno` = '$question'";
$result = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($result) > 0)
{
while ($row = mysql_fetch_assoc($result))
{
echo $row['feedback'.$newno].'<br />';
}
}
else
{
echo 'No Feedback Found';
}
$sql2="select `truefalse".$newno."`from `question` where `testno` = '".$testno."' and `questionno` = '$question'";
$rs = mysql_query($sql) or die(mysql_error());
$row=mysql_fetch_object($rs);
$answer = $row->truefalse.$newno;
Switch($answer)
{
case "True":
$score = $scores + (1);
break;
case "False":
$score = $scores;
break;
echo $score;
}
?>