bram van der kuip bram van der kuip - 1 year ago 190
MySQL Question

Node js insert Mysql doesnt work

this is part of the code i use

var insertedData = {
name: 'testname',
score: '1337'
connect.query('INSERT INTO table SET ?', insertedData, function(error, result){

and this is the error i got

{ [Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check
the manual that corresponds to your MySQL server version for the right
syntax to use near 'table SET
= 'Hek',
= '12'' at line
1]code: 'ER_PARSE_ERROR', errno: 1064, sqlState: '42000',index: 0 }

Answer Source

table is a reserved word in MySQL. I'd advise to rename your table to something else. If this is absolutely not a possibility for you, you can escape it with backticks:

connect.query('INSERT INTO `table` SET ?', insertedData, function(error, result){
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download