javascript - 嵌套查询在 Node.js 和 MySQL 中不起作用
问题描述
我的代码如下。
我得到的错误是在包含 UPDATE 语句的查询语句中。
为什么我得到一个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 'WHERE email = 'test@gmail.com'' at line 1
?
控制器
...
exports.login = (req, res, next) => {
const { email, password } = req.body;
const secretKey = req.app.get('jwt-secret');
let sql = `SELECT * FROM user WHERE email = ?`;
User.query(sql, [email], (err, result) => {
...
if (result[0] === undefined || result[0].password !== encrypted) {
res.status(300).send('ID, PS check plz');
} else {
const token = jwtSign(secretKey, result[0].userId, email);
sql = `UPDATE user SET token = ? WHERE email = ?`;
User.query(sql, [token, email], (err, result) => {
console.log(err);
if (err) {
return next(err);
}
...
});
}
});
};
解决方案
推荐阅读
- angular - Chart.js - 未使用格式化程序显示数据标签
- javascript - JavaScript 我们可以将 then() 中应该包含的内容带入带参数的方法中并调用它
- android - 使用 react-native-sqlite-storage 反应原生离线应用程序
- c# - Windows 窗体中的 Speech-To-Text 应用程序 [离线]
- microsoft-graph-api - 通过图表设置 AllowGuestsToAccessGroups
- python-3.x - 将数据框中的 0 替换为 1
- sql - Sql - 我正在尝试计算(总和)值介于数字范围之间的列
- sql - 使用自由文本 sql 服务器的电子邮件 ID 过滤器
- amazon-web-services - 如何使用 aws cdk 生成 IAM 服务特定凭证?
- flutter - 颤振:使用等待时的区别