0

我正在使用以下内容进行测验,它检查表格以查看用户是否已经发布了问题的答案并且没有敲击提交按钮,我遇到的问题是它没有将信息发布到数据库出于某种奇怪的原因。如果我取出 if 语句和第一个数据库查找并发布数据它工作正常,但是当我首先检查第一个查询的结果时,它似乎不起作用,即使用户没有提交回答呢。

 <?php
 $quizID = $_GET['quiz'];
$userID = $_GET['user'];
$quizselectanswer = $_POST['quizselectanswer'];
$cf_created = date("y/m/d");
$questionID = $_POST['questionID'];

// Check to see if user answered question already
 $result = mysql_query("SELECT questionID,userID FROM itsnb_chronoforms_data_answerquiz WHERE     questionID='$questionID' AND userID='$userID' LIMIT 1") or die(mysql_error());

while($row = mysql_fetch_array($result))
{ 
if (empty($row))
{
    mysql_query("INSERT INTO itsnb_chronoforms_data_answerquiz (cf_created,     questionID,quizselectanswer,quizID, userID)
    VALUES ('$cf_created', '$questionID', '$quizselectanswer', '$quizID','$userID')") 
    or     
    die(mysql_error());
}else{

}
}
?>

我的数据库看起来像这样itsnb_chronoforms_data_answerquiz cf_id, cf_uid, cf_created, cf_modified, cf_ipaddress, cf_user_id, questionID, quizselectanswer, quizID, userID.

4

1 回答 1

1

像这样尝试它可能会帮助你

// Check to see if user answered question already
 $result = mysql_query("SELECT * FROM itsnb_chronoforms_data_answerquiz WHERE questionID='$questionID' AND userID='$userID' LIMIT 1") or die(mysql_error());

$row = mysql_fetch_array($result);
if(!empty($row)) 
{
    while($row){
        //some statement
    }
}else{
    mysql_query('INSERT INTO itsnb_chronoforms_data_answerquiz (cf_created, questionID,quizselectanswer, quizID, userID)
    VALUES ("'.$cf_created.'", "'.$questionID.'", "'.$quizselectanswer.'", "'.$quizID.'","'.$userID.'")') or die(mysql_error());
}
?>
于 2012-11-29T14:23:00.973 回答