我正在尝试插入数据,如果数据存在我需要更新数据。我有一个查询但是当我在phpmyadmin中执行此查询时出现错误
在分析过程中发现了2个错误。
无法识别的关键字。 (位置224处的“KEY”附近)
预计会有表达。 (位置235处的“SET”附近)
下面是我的查询:
INSERT INTO usr_data (usr_id, login, firstname, gender, street, zipcode, country, phone_mobile, email)
VALUES('265', '100236', 'gouni', 'M', 'jlnklmana', '502103', 'telangana', '+60123654', 'email@email.com')
ON DUPLICATE KEY UPDATE SET login=100236,usr_id=265,firstname=gouni,gender=M,street=jlnklmanahghg,zipcode=502103,country=telangana,phone_mobile=+60123654,email=email@email.com
答案 0 :(得分:0)
试试这个。
更正了查询:
INSERT INTO usr_data
(usr_id, login, firstname, gender, street, zipcode, country, phone_mobile, email)
VALUES
('265', '100236', 'gouni', 'M', 'jlnklmana', '502103', 'telangana', '+60123654', 'email@email.com')
ON DUPLICATE KEY
UPDATE
login='100236',usr_id='265',firstname='gouni',gender='M',street='jlnklmanahghg',zipcode='502103',country='telangana',phone_mobile='+60123654',email='email@email.com'
您必须从查询中删除SET
个关键字。
一般语法:
INSERT INTO t1 (a,b,c) VALUES (1,2,3)
ON DUPLICATE KEY UPDATE c=c+1;
答案 1 :(得分:0)
删除单词SET
INSERT INTO usr_data (usr_id, login, firstname, gender, street, zipcode, country, phone_mobile, email)
VALUES('265', '100236', 'gouni', 'M', 'jlnklmana', '502103', 'telangana', '+60123654', 'email@email.com')
ON DUPLICATE KEY UPDATE login='100236',usr_id='265',firstname='gouni',gender='M',street='jlnklmanahghg',zipcode='502103',country='telangana',phone_mobile='+60123654',
email='email@email.com'