sql查询无法在nodejs应用中正常工作

时间:2019-07-31 07:01:17

标签: mysql node.js express

 payment:(req,res)=>{
        let twothoudand = req.body.twothoudand;
        let fivehundred = req.body.fivehundred;
        let twohundred = req.body.twohundred;
        let hundred = req.body.hundred;
        let fifty = req.body.fifty;
        let twenty = req.body.twenty;
        let ten = req.body.ten;
        let id_list = req.body.sel;

        let sql = "INSERT INTO `paymententry_truck`(`Payment_ID`, `Date`, `2000`, `500`, `200`, `100`, `50`, `20`, `10`) VALUES(NULL, CURRENT_TIMESTAMP, '" + twothoudand + "', '" + fivehundred + "','" + twohundred + "','" + hundred + "','" + fifty + "','" + twenty + "','" + ten + "'); `UPDATE` trans1 SET paidStatus = LAST_INSERT_ID() WHERE trans1.Sr_NO IN(" + id_list + ");"
        let query = conn.query(sql,(err, results)=>{
            if(err){
                console.log(sql);
            }else{
                res.redirect('/');
            }

        });
    }

我的nodejs应用程序中有一个MYSQL查询,如果我在phpmyadmin中执行查询,则该查询工作正常。但是,当我使用node.js应用程序将相同的查询发送到服务器时,查询抛出错误号1064

INSERT INTO `paymententry_truck`(`Payment_ID`, `Date`, `2000`, `500`, `200`, `100`, `50`, `20`, `10`) VALUES(NULL, CURRENT_TIMESTAMP, \'7\', \'1\',\'1\',\'\',\'\',\'\',\'8\'); UPDATE trans1 SET paidStatus =LAST_INSERT_ID() WHERE trans1.Sr_NO IN(10);

当我在phpmyadmin中粘贴相同的查询时,这是我的应用程序发送到服务器的查询正在运行的查询,但是当Node.js应用程序将相同的查询发送到服务器时,该查询无法使用。

  code: 'ER_PARSE_ERROR',
  errno: 1064,
  sqlMessage:
   'You have an error in your SQL syntax; check the manual that corresponds to y
our MariaDB server version for the right syntax to use near 

\'UPDATE trans1 SET
paidStatus = LAST_INSERT_ID() WHERE trans1.Sr_NO IN(10)\' at line 1',
  sqlState: '42000',
  index: 0,


  sql:'INSERT INTO `paymententry_truck`(`Payment_ID`, `Date`, `2000`, `500`, `200`, `100`, `50`, `20`, `10`) VALUES(NULL, CURRENT_TIMESTAMP, \'7\', \'1\',\'1\',\'\',\'\',\'\',\'8\'); UPDATE trans1 SET paidStatus =LAST_INSERT_ID() WHERE trans1
.Sr_NO IN(10);' }

预期结果是在表Paymententry_truck中添加具有给定值的行,并将最后一个条目号更新到表trans1列paidStatus中,其中(10)中的Sr_No;

0 个答案:

没有答案