<?php
$connection=mysql_connect('localhost','root',"");
if(!$connection)
{
die("database connection failed".mysql_error());
}
$db_select=mysql_select_db("db",$connection);
if(!$db_select)
{
die("database connection failed".mysql_error());
}
if(!isset($_POST['submit']))
{
echo "<form method=\"post\" action=\"test1.php\">";
$sub_result=mysql_query("SELECT * from test where tid='1' order by rand() limit 0,2",$connection);
if(!$sub_result)
{
die("database query failed". mysql_error());
}
while ($sub_row=mysql_fetch_array($sub_result))
{
$id=$sub_row["qno"];
$ques=$sub_row["ques"];
$opt1=$sub_row["opt1"];
$opt2=$sub_row["opt2"];
$opt3=$sub_row["opt3"];
$opt4=$sub_row["opt4"];
$ans=$sub_row["ans"];
echo "<h3>Q".$id." :".$ques."</br></h3>";
echo"</br>
$opt1
<input type= radio name=\"{$id}\" value=\"{$opt1}\" >
</br>
$opt2
<input type= radio name=\"{$id}\" value=\"{$opt2}\">
</br>
$opt3
<input type= radio name=\"{$id}\" value=\"{$opt3}\">
</br>
$opt4
<input type= radio name=\"{$id}\" value=\"{$opt4}\">
</br></br>";
}
echo"<input type='submit' value='see how you did it' name='submit'>";
echo"</form>";
}
if(isset($_POST['submit']))
{
$total=0;
$answer=mysql_query("select qno,ans from test",$connection);
while($ans=mysql_fetch_assoc($answer))
{
if($_POST[$ans['qno']] === $ans['ans'])
{
$total++;
}
else
{
}
}
echo"<p align=center><b>I Got $total</b>";
}
?>
出现错误“第 60 行中的未定义偏移量,我正在这里验证答案。”