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

I recently encountered a similar issue while trying to pass a parameter into a string in Node JS.

In the end, I was able to get a dynamic insertion into my MySQL database by using this line :

insertIntoNodeDirectory( '2', '"' + testMacAddress[0] + '"', '1');

This would enter the integer value 2, the string value contained in the testMacAddress array at index 0, and the integer value 1.

If i used this line: insertIntoNodeDirectory( '2', '" + testMacAddress[0] + "', '1');

without the additional single quotes around testMacAddress, the value inserted into the database was the string 'testMacAddress[0]'. Not what I wanted.


var _name = req.body.name
var _age = req.body.age
var _table = 'people'

const _query = "INSERT INTO " + _table + " (name, age) VALUES ('" + _name + "', '" + _age + "' );"

This is work for me, main issue occur in query.


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

Tags:

Mysql

Sql