我以前来过这里,这不会是我最后一次:P。我现在正在做一个项目,该项目由用户完成的调查组成,结果将保存到特定的用户 ID 中,该用户 ID 稍后会被 php 文件获取。我当前遇到的问题是在尝试提交表单时出现以下错误
13
您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的 '' 附近使用正确的语法
数字 13 与分配给我正在使用的测试用户的用户 ID 相关。使用 ID 12 时,所有内容都会毫无问题地注册......有什么建议吗?
<?php
ob_start();
error_reporting(E_ALL);
ini_set('display_errors', "On");
session_start();
if (!isset($_SESSION['username'])) {
header('location:/login.php');
}
$con= mysqli_connect("localhost", "root", "admin", "animator");
$query= "SELECT iduser FROM `animator`.`user` WHERE idaccount = " . $_SESSION['idaccount'] . ";";
$result= mysqli_query($con, $query);
$info= mysqli_fetch_array($result);
$userid= $info['iduser'];
$query= "SELECT idsurvey FROM `animator`.`questionnaire` WHERE iduser = " .$userid. ";";
$result2= mysqli_query($con, $query) or die(mysqli_error($con));
$info2= mysqli_fetch_array($result2);
$surveyid = $info2['idsurvey'];
echo $userid . "<br/>";
echo $surveyid;
$result->close();
for ($i = 0; $i < 18; $i++) {
$qnum= $i + 1;
$qstr= "q" . $qnum;
$query= "SELECT * FROM `animator`.`question` WHERE idquestion = '" . $qstr . "' AND idsurvey = 0 ;";
$qresult= mysqli_query($con, $query) or die(mysqli_error($con));
$qinfo= mysqli_fetch_array($qresult);
$question= $qinfo['question'];
$query= "SELECT * FROM `animator`.`question` WHERE idquestion = '" . $qstr . "' AND idsurvey = " . $surveyid . ";";
$qresult= mysqli_query($con, $query) or die(mysqli_error($con));
if (mysql_num_rows($qresult) > 0){
$query = "UPDATE `animator`.`question` SET answer = '" . $_POST[$qstr] . "' WHERE idquestion = '" . $qstr . "' AND idsurvey = " . $surveyid . ";";
}
else{
$query = "INSERT INTO `animator`.`question` (idquestion, idsurvey, question, answer)";
$query .= "VALUES ('" . $qstr . "', " . $surveyid . ", '" . $question . "', '" . $_POST[$qstr] . "');";
}
echo $query . "<br/>";
mysqli_query($con, $query) or die(mysqli_error($con));
echo "Inserted question " . $qnum;
}
echo "Questionnaire submitted successfully!";
?>