我有一个包含文本字段的表单。当用户提交数据时,它会根据表格中的“答案”列检查输入的数据是否正确。
但这是问题所在 - 它接受任何内容,而无需根据正确答案验证提交的文本字段。
我是php新手,所以请帮忙。这是代码。
$myuser = $_SESSION["myusername"]; $mypass = $_SESSION["mypassword"];
$host="localhost"; // Host name
$username="f123"; // Mysql username
$password="t"; // Mysql password
$db_name="f"; // Database name
$tbl_name="members"; // Table name
$tbl_name2="quiz"; // Table name 2
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
if(isset($_POST['qno']))
{
$sql3="SELECT * FROM $tbl_name2 WHERE id='".$_POST['qno']."'";
$result3=mysql_query($sql3);
$disp3=mysql_fetch_assoc($result3);
$sql4="SELECT * FROM $tbl_name WHERE username='$myuser' and password='$mypass'";
$result4=mysql_query($sql4);
$disp4=mysql_fetch_assoc($result4);
if($disp3['Answer']==$_POST['Answer'])
{
$sql5="UPDATE $tbl_name SET level_crossed='".($disp4['level_crossed']+1)."',
Score='".($disp4 ['Score']+1)."' WHERE username='$myuser' and password='$mypass'";
$result5=mysql_query($sql5);
}
else {
$sql5="UPDATE $tbl_name SET level_crossed='".($disp4['level_crossed']+1)."'
WHERE username='$myuser' and password='$mypass'";
$result5=mysql_query($sql5);
<form name="quizq" action="quiz.php" method="post" >
<input name="qno" type="hidden" value="<?php echo $disp['level_crossed']+1; ?>" />
<input type="text" name="Answer" />
<input type="submit" value="Submit Answer" /></p>
</form>