gpt4 book ai didi

php - 发布的结果不会保存到 mysql 数据库,即使不存在记录

转载 作者:行者123 更新时间:2023-11-29 14:10:09 25 4
gpt4 key购买 nike

我正在做一个测验,它会检查表格以查看用户是否已经发布了问题的答案并且没有敲击提交按钮,我遇到的问题是它没有发布由于某种奇怪的原因将信息存入数据库。如果我取出 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_idcf_uidcf_createdcf_modified ,cf_ipaddress ,cf_user_id ,questionID,quizselectanswer,quizID ,用户 ID.

最佳答案

尝试这样可能会对你有帮助

// 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());
}
?>

关于php - 发布的结果不会保存到 mysql 数据库,即使不存在记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13627146/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com