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) + ")";
make
" + convID + "
to
'" + convID + "'
Most likely its a string and the data type is varchar so u need to enclose within single quote.
I had a similar problem myself, I also didn't have all of my column names specified correctly. here is the code that finally worked.
var queryString = "INSERT INTO " + table + " (columnText, columnBool) VALUES ('" + val + "', FALSE);"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With