MySql从节点Js插入错误

我有这样的MySQL表:

在这里输入图像说明

下面是我想从哪里插入数据到MySQL表的代码:

var data = { id : 1, custname : input.custname, custemail : input.custemail, ordertype : input.ordertype, noorder : input.noorder, orderdate : input.orderdate }; var query = connection.query('INSERT INTO order SET ?', data, function(err,rows) { if (err) console.log("Error inserting : %s ",err ); res.render('createorder', {title :"Order Created Successfully"}); }); 

但是给我以下错误:

 INSERT INTO order SET `id` = 1, `custname` = 's', `custemail` = 's@gmail.com', `ordertype` = 'Chalbhaja', `noorder` = 2, `orderdate` = '2015-07-24T16:07:58.684Z' Error inserting : 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 'order SET `id` = 1, `custname` = 's', `custemail` = 's@gmail.com', `ordertype` =' at line 1 

order字是MySQL中的一个关键字。 尽pipe可以有一个名为order的表。 您只需在查询中将其转义即可,如下所示:

 var query = connection.query('INSERT INTO `order` SET ?', data, function(err,rows) { if (err) console.log("Error inserting : %s ",err ); res.render('createorder', {title :"Order Created Successfully"}); });