小编典典

MySQL插入错误:ER_BAD_FIELD_ERROR:“字段列表”中的未知列“ 2525”

sql

var convID = 2525;
var contactUsername = 'blabla';
var userId = 100;
var contactId = 200;

var sql = "INSERT INTO contacts (FK_OWNERID, FK_USERID, FC_CONTACTNAME, `CONVERSATION_ID`)
                     VALUES (" + mysql.escape(userId) + "," + mysql.escape(contactId) + "," + mysql.escape(contactUsername) + "," + convID + "),
                     (" + mysql.escape(contactId) + "," + mysql.escape(userId) + "," + mysql.escape(username) + "," + convID + ")";

错误:ER_BAD_FIELD_ERROR:“字段列表”中的未知列“
2525”对于CONVERSATION_ID和FC_CONTACTNAME而言,字段均为varchar(32),对于其他2个字段均为int。

此查询出了什么问题?我什至放回了句号CONVERSATION_ID,它认为convID变量是一列…

编辑:

如果我的查询就是这样,那么它可以工作:

        var sql = "INSERT INTO contacts (`FK_OWNERID`, `FK_USERID`, `FC_CONTACTNAME`)
                 VALUES (" + mysql.escape(userId) + "," + mysql.escape(contactId) + "," + mysql.escape(contactUsername) + "),
                 (" + mysql.escape(contactId) + "," + mysql.escape(userId) + "," + mysql.escape(username) + ")";

阅读 271

收藏
2021-03-23

共1个答案

小编典典

制作

" + convID + "

'" + convID + "'

最有可能是字符串,数据类型是varchar,因此您需要用单引号引起来。

2021-03-23