Dany Dany - 2 months ago 6
SQL Question

MySQL insert error : ER_BAD_FIELD_ERROR: Unknown column '2525' in 'field list'

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


`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.

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

Edit:

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

Answer

make

" + convID + "

to

'" + convID + "'

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

Comments