所以我有这个问题,我有点搞不懂逻辑是怎么工作的。我正在创建一个新的用户注册方法,里面有一个检查用户是否使用同一封电子邮件的方法。我用 Postman 当张贴查询。
第一个查询工作正常,包括电子邮件检查方法和注册新邮件,而对于第二个查询,电子邮件检查工作,但注册新邮件不工作, Postman 一直加载,直到一分钟左右,直到它说'无法得到答复'。
第一个(作品)
exports.postContact = router.post("/api/users/new", (req, res) => {
var today = new Date();
var users = {
"first_name": req.body.first_name,
"last_name": req.body.last_name,
"email": req.body.email,
"password": req.body.password,
"created": today,
"modified": today
}
var email = req.body.email;
mySQL.query('SELECT * FROM users WHERE email = ?', [email], function (err, results, fields) {
if (results.length > 0) {
if (results[0].email == email) {
res.send({
"code": 204,
"status": 'Failed',
"message": "This email address is already registered, please login instead"
});
}
}
else {
mySQL.query("INSERT INTO users SET ?", users,
(err, results, fields) => {
if (err)
res.send({
"code": 400,
"status": 'Failed',
"message": 'Something wrong with the connection'
})
res.send({
"code": 400,
"status": 'Success',
"message": 'User is successfully registered'
})
}
);
}
});
});
第二个(不起作用)
exports.postContact = router.post("/api/users/new", (req, res) => {
var today = new Date();
var users = {
"first_name": req.body.first_name,
"last_name": req.body.last_name,
"email": req.body.email,
"password": req.body.password,
"created": today,
"modified": today
}
var email = req.body.email;
mySQL.query('SELECT * FROM users WHERE email = ?', [email], function (err, results, fields) {
if (results.length > 0) {
if (results[0].email == email) {
res.send({
"code": 204,
"status": 'Failed',
"message": "This email address is already registered, please login instead"
});
}
else {
mySQL.query("INSERT INTO users SET ?", users,
(err, results, fields) => {
if (err)
res.send({
"code": 400,
"status": 'Failed',
"message": 'Something wrong with the connection'
})
res.send({
"code": 400,
"status": 'Success',
"message": 'User is successfully registered'
})
}
);
}
}
});
});
1条答案
按热度按时间vpfxa7rd1#
可能需要刷新sql语句。
我相信这是正确的:
mysql的正确插入查询:
这里有一个链接供参考。