gpt4 book ai didi

mysql - '无法读取未定义的属性 'length'' nodeJS Mysql

转载 作者:行者123 更新时间:2023-11-30 22:34:02 25 4
gpt4 key购买 nike

无法执行。当我单独执行查询时,我没有收到任何错误。

   app.post('/Fu',function(req,res,next){

var username = req.body.uname;
var pass = req.body.pwd;

con.query(' SELECT name FROM fun WHERE name = "' +username+'" ; SELECT password FROM fun WHERE password = "' +pass+'" ',function(err, results,fields) {



if (results.length > 0) {

var w = results[0].password;

var q = results[1].name;
//console.log(q);
console.log('Login was successful');
}

else {
console.log('Login was not successful');
}

});

res.send("success1");

});

有人可以帮我解决这个问题吗?提前致谢。

最佳答案

首先尝试改变你的:

 con.query(' SELECT name FROM fun WHERE name = "' +username+'" ; SELECT password FROM fun WHERE password = "' +pass+'" ',function(err, results,fields) {

到:

 con.query(' SELECT name, password FROM fun WHERE name = "' +username+'" AND password = "' +pass+'" ',function(err, results,fields) {
if (err) throw err;

关于mysql - '无法读取未定义的属性 'length'' nodeJS Mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33041207/

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