【问题标题】:SQl statement of DELETE query giving errorDELETE查询的SQL语句给出错误
【发布时间】:2020-06-29 05:24:39
【问题描述】:

大家好,我的“store_ip”表中有数据,我在其中存储用户的电子邮件和他的 IP 地址。因此,一旦用户单击注销按钮,我需要从“store_ip”中删除与该用户相关的行,所以我所做的是

app.post("/user_logout",  function (req, res) {
  var postData = req.body;

 console.log(typeof(postData.email))

  connection.query(
    "DELETE FROM store_ip WHERE email = " + postData.email,
    postData,
    function (error, results, fields) {
      if (error) throw error;

      res.end(JSON.stringify({ status: 200, message: "Login Data deleted!" }));
    }
  );
});

formdata 有一封电子邮件,但我仍然收到错误

   sqlMessage:
  '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 \'@gmail.com\' at line 1',
  sqlState: '42000',
  index: 0,
  sql: 'DELETE FROM store_ip WHERE email = ratnabh2616@gmail.com' }

【问题讨论】:

  • 您需要将您的 SQL 字符串参数封装在引号中。 "DELETE FROM store_ip WHERE email = '"+ postData.email + "'",
  • @user3647971 谢谢

标签: mysql sql node.js


【解决方案1】:

问题在于您需要在电子邮件前添加 '。

 "DELETE FROM store_ip WHERE email = " + postData.email,

应该是这样的

"DELETE FROM store_ip WHERE email = '" + postData.email+"'",

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多