gpt4 book ai didi

javascript - 使用mysql通过javascript访问全局函数

转载 作者:行者123 更新时间:2023-11-29 18:10:50 25 4
gpt4 key购买 nike

我试图在访问内容之前验证用户。我已经在全局声明了函数并将其传递到体内。当我运行它时,出现错误:用户不存在。请让我知道我哪里出错了。

function validate(user_id){ 
var user_id = db.query('select user_id from user WHERE user_id = ?', [user_id],
function(error,rows) {
if (user_id != user_id) {
return false;
} else {
return true;
}
});
}

router.post('/addcustomerskills', function(req,res) {
if (validate(user_id == true)) {
return true;
// my code should execute
}else {
response.success= false;
response.mssg = "User Doesn't Exist";
res.json(response);
}

最佳答案

function validate(user_id, req, res){
db.query('select user_id from user WHERE user_id = ?', [user_id], function(error,rows) {
if (error || rows.length === 0) {
var response = {}
response.success= false;
response.mssg = "User Doesn't Exist";
res.json(response);
} else {
// my code should execute
return true;
}
});
}

router.post('/addcustomerskills', function(req,res) {
validate(req.body.user_id, req, res);
})

关于javascript - 使用mysql通过javascript访问全局函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47429174/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com