本文介绍了MySQL插入错误:ER_BAD_FIELD_ERROR:“字段列表"中的未知列"2525"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

`Error: ER_BAD_FIELD_ERROR: Unknown column '2525' in 'field list'Fields are varchar(32) for both CONVERSATION_ID and FC_CONTACTNAME and ints for the 2 others.

此查询出了什么问题?我什至把反引号放在CONVERSATION_ID周围,它认为convID变量是一列...

What's wrong with this query? I even put the backticks around CONVERSATION_ID and it thinks the convID variable is a column...

如果我的查询就是这样,那就行了:

If my query is just that, then it works:

        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) + ")";

推荐答案

制作

" + convID + "

'" + convID + "'

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

Most likely its a string and the data type is varchar so u need to enclose within single quote.

这篇关于MySQL插入错误:ER_BAD_FIELD_ERROR:“字段列表"中的未知列"2525"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 18:28