我试图更新一个表,它显示了一个SQL语法错误,但它正确地更新了表。我真的不确定背后的原因是什么,我只是不想完全消除这个错误。
Error: 1
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1
这就是功能:
function logTime($time){
$sql1 = mysqli_query($this->con, "UPDATE `pilots` SET `active`='0',`total_time`='".$time."' WHERE username = '".$this->whoMe()."'");
if (mysqli_query($this->con, $sql1)) {
header('Location: index.php?pausedtime');
die();
}
else {
echo "Error: " . $sql1 . "<br>" . mysqli_error($this->con);
}
}
这是因为您使用了mysqli_query()
两次。。。$sql1
行应该足够了。试试这个:
function logTime($time){
$sql1 = mysqli_query($this->con, "UPDATE `pilots` SET `active`='0',`total_time`='".$time."' WHERE username = '".$this->whoMe()."'");
if($sql1){
header('Location: index.php?pausedtime');
die();
} else {
echo "Error: " . $sql1 . "<br>" . mysqli_error($this->con);
}
}
还要注意,出于安全原因(至少),此类查询应使用准备好的语句执行。