【发布时间】: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 谢谢