我总是遇到这样的问题或错误:
您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以便在第1行''kunci = 1 WHERE date ='2013-09-01'AND user_id ='2''附近使用正确的语法
这是我的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表中为时间表得到了'shift'结构的整理。我不知道它是否会起作用。
我的表=时间表:
name: shift, type:varchar(10), collation:latin1_swedish_ci.
有人能帮助我吗?非常感谢你。
答案 0 :(得分:5)
$sql1=("UPDATE timetable SET shift='A' kunci=1 WHERE date='".$mcdate."' AND user_id='".$mcstaff."'");
应该是
$sql1=("UPDATE timetable SET shift='A', kunci=1 WHERE date='".$mcdate."' AND user_id='".$mcstaff."'");
^------ missing comma