{ Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''mom12345'' at line 1}
我正在尝试使用节点js在mysql中编写一个登录查询,但出于某种原因,我不断收到上述错误。请有人帮助我。
var logininfo={
username:username,
password:password
};
con.query('SELECT id FROM userinfo WHERE username=? and password ?',logininfo, function (error, results, fields) {
if (error) {
console.log("error ocurred",error);
} else {
console.log('The solution is: ', results);
if (results.length > 0) {
if ([0].password == password) {
console.log("Login Successful");
}
else {
console.log("Username and password donot match");
}
}
}
})
}
答案 0 :(得分:1)
你忘了等于签名
WHERE username=? and password = ?
---^
答案 1 :(得分:0)
您的第二个参数应该是参数数组而不是对象。
所以改变:
var logininfo={
username:username,
password:password
};
要:
var logininfo=[
username,
password
];