Question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 
131

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

// pick the database to use
mysql_select_db("testdb",$conn);


// 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


echo
"<tr><td colspan=4><br><b>$id</b></td></tr>";
echo
"<TD>$testField<input type=hidden name=$testField value=\"$testField\"> <br>
</td></tr>
<TD>a)<input type=radio name=$testFielda 
value=\"$testFielda\">$testFielda</td></tr>
<TD>b)<input type=radio name=$testFieldb 
value=\"$testFieldb\">$testFieldb</td></tr>
<TD>c)<input type=radio name=$testFieldc 
value=\"$testFieldc\">$testFieldc</td></tr>
<TD>d)<input type=radio name=$testFieldd 
value=\"$testFieldd\">$testFieldd</td></tr>";
}
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)
  {
  $score++;
  }

 }

 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 
$testFielde</td></tr>";
}
else {
echo "<tr><td>&raquo;you answered ${$q}. The answer is $testFielde</td></tr>";
}

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

?>

[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux