gpt4 book ai didi

php - MySQL 错误, "You have an error in your SQL syntax"

转载 作者:行者123 更新时间:2023-12-01 00:48:24 24 4
gpt4 key购买 nike

<分区>

我总是遇到这样的问题或错误:

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 `'kunci=1 WHERE date='2013-09-01' AND user_id='2'' at line 1

这是我的 php 代码:

if(isset($_POST['mc'])) {

$mcdate = $_POST['mcdate'];
$mcstaff = $_POST['mcstaff'];

$sql = mysql_query("
SELECT *
FROM timetable
WHERE
date ='" . $mcdate . "'
AND shift='O'
AND user_id='" . $mcstaff . "'");

$counto = mysql_num_rows($sql);
echo $counto;

if ($counto == 0) {

$sql1 = "
UPDATE timetable
SET
shift='A'
kunci=1
WHERE
date='" . $mcdate . "'
AND user_id='" . $mcstaff . "'";
mysql_query($sql1) or die(mysql_error());

$sql2 = mysql_query("
SELECT *
FROM timetable
WHERE date ='" . $mcdate . "'
AND shift='M'");
$countm=mysql_num_rows($sql2);
//echo $countm;

$sql3 = mysql_query("
SELECT *
FROM timetable
WHERE
date ='" . $mcdate . "'
AND shift='E'");
$counte=mysql_num_rows($sql3);
//echo $counte;

//balance shift
if($counte==$countm) {

$rand=rand(0, 2);
if($rand==0) {
$shift = 'M';
} else {
$shift = 'E';
}

} else if ($countm>$counte) {

$shift = 'E';

} else if ($counte>$countm) {

$shift = 'M';

}

} else if ($counto == 1) {

echo "Staff already Off";

}
}

我也试过用反引号将数据库、表和列名称括起来以防止此类冲突,但仍然出现此错误。

我还意识到在我的 MySQL 时间表表中得到了“类次”结构的排序规则。不知道有没有效果。

我的 table = 时间表:

name: shift, type:varchar(10), collation:latin1_swedish_ci. 

有人可以帮助我吗?非常感谢。

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