Dear friends,
I was trying to make online quiz system using php and mysql.
When I added code to score the quiz,  it gives me parse error at line 131. My 
total code line isn't more than 120.

Any comments,or any other code to score the quiz, please
Parse error: parse error, unexpected $end in C:\webroot\display.php on line 

//Below is the code
// open the connection
$conn = mysql_connect("localhost", "", "");

// pick the database to use

// create the SQL statement
$sql = "SELECT * FROM testTable";

// execute the SQL statement
$result = mysql_query($sql, $conn) or die(mysql_error());
//go through each row in the result set and display data

if (!$submit) {

 echo "<form method=post action=$PHP_SELF>";
 echo "<table border=0>";

while ($newArray = mysql_fetch_array($result)) {
 // give a name to the fields
    $id  = $newArray['id'];
    $testField = $newArray['testField'];
  $testFielda = $newArray['testFielda'];
  $testFieldb = $newArray['testFieldb'];
  $testFieldc = $newArray['testFieldc'];
  $testFieldd = $newArray['testFieldd'];

    //echo the results onscreen

"<tr><td colspan=4><br><b>$id</b></td></tr>";
"<TD>$testField<input type=hidden name=$testField value=\"$testField\"> <br>
<TD>a)<input type=radio name=$testFielda 
<TD>b)<input type=radio name=$testFieldb 
<TD>c)<input type=radio name=$testFieldc 
<TD>d)<input type=radio name=$testFieldd 
echo "</table>";

echo "<input type='submit' value='See how you did' name='submit'>";

echo "</form>";


elseif ($submit)

 $score = 0;
 $total = mysql_num_rows($result);
  while ($result = mysql_fetch_array($result))


   $testFielde = $result["testFielde"];
   $q = $result["q"];

  if ($$q == $testFielde)


 echo "<p align=center><b>You scored $score out of $total</b></p>";
 echo "<p>";

 if   ($score == $total) {
 echo "Congratulations! You got every question right!";
 elseif ($score/$total < 0.34) {
 echo "Oh dear. Not the best score, but don't worry, it's only a quiz.";
 elseif ($score/$total > 0.67) {
 echo "Well done! You certainly know your stuff.";
 else {
 echo "Not bad - but there were a few that caught you out!";

echo "</p>";

echo "<p>Here are the answers:";

echo "<table border=0>";
$result = mysql_query("SELECT * FROM $testtable ORDER BY id",$testdb);
while ($row = mysql_fetch_array($result)) {

$testField = $row["testFieldetestFielde"];
$testFielde = $row["testFielde"];
$q = $row["q"];

echo "<tr><td><br>$testField</td></tr>";

if ($$q == $testFielde)
  echo "<tr><td>&raquo;you answered ${$q}, which is correct</td></tr>";
elseif ($$q == "") {
echo "<tr><td>&raquo;you didn't select an answer. The answer is 
else {
echo "<tr><td>&raquo;you answered ${$q}. The answer is $testFielde</td></tr>";

echo "</table></p>";


Reply via email to