Php,ON DUPLICATED KEY UPDATE。错误?

时间:2017-03-08 10:31:47

标签: php mysql

我已阅读文档,无法查看我的声明有什么问题

错误发生在'KEY'

    INSERT INTO employeedetails (userid,ref,name,department,commenced) VALUES 
('$userid','$ref','$name','$department','$commenced')
ON DUPLICATE KEY UPDATE
ref='" . $ref . "',
name = '" . $name . "',
department = '" . $department . "',
commenced = '" . $commenced . "'
WHERE userid=" . $userid;

非常感谢!

编辑:

主键是'用户ID'

        INSERT INTO employeedetails (userid,ref,name,department,commenced) 
        VALUES ('1','11','','','2017-03-08 00:00:00') ON DUPLICATE KEY UPDATE ref='11', 
        name = '', department = '', commenced = '2017-03-08 00:00:00' WHERE userid=1

错误是:无法识别的关键字。 (位置529处的“KEY”附近)

1 个答案:

答案 0 :(得分:0)

删除WHERE仍会出现错误但运行正常

INSERT INTO employeedetails (userid,ref,name,department,commenced) 
        VALUES ('1','11','','','2017-03-08 00:00:00') ON DUPLICATE KEY UPDATE ref='11', 
        name = '', department = '', commenced = '2017-03-08 00:00:00'