CREATE TABLE IF NOT EXISTS `leave` (
`leaveid` int(11) NOT NULL AUTO_INCREMENT,
`employee_num` varchar(50) NOT NULL,
`date_start` date NOT NULL,
`date_end` date NOT NULL,
`total_no_day` int(11) NOT NULL,
PRIMARY KEY (`leaveid`)
)
我尝试通过执行SQL和php代码插入一个条目。两种方法都返回相同的错误:#1064 - 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 'leave ('employee_num', 'date_start', 'date_end', 'total_no_day') values ('1007',' at line 1
这是SQL代码:
INSERT INTO leave ('employee_num', 'date_start', 'date_end', 'total_no_day') values ('1007', '2014-04-01', '2014-04-04', '4')
这是PHP代码:
$qry="INSERT INTO leave ('employee_num', 'date_start', 'date_end', 'total_no_day')
values ('$empID', '$dFr', '$dTo', '$noDay')";
mysql_query($qry);
他们都返回了同样的错误......我在这里做错了什么?
答案 0 :(得分:4)
您在列名称周围添加单引号。您应该使用反引号字符:
INSERT INTO `leave` (`employee_num`, `date_start`, `date_end`, `total_no_day`)
VALUES ('1007', '2014-04-01', '2014-04-04', '4')