我正在尝试在mysql中选择一行,在其中我的变量req.body.email在列Email_Address中找到 这是我的代码段
app.post('/ login',function(req,res){
con.query("select * from people where Email_address= "+ req.body.email, (err, res) => {
if(err) {
console.log('the email '+ req.body.email +'does not exist in the database');
throw err;
}
else{
console.log('selected');
if(password == req.body.password)
//res.redirect('index', { title: 'Hey', message: 'Hello there!' });
res.send('hello');
}
});
但我在下面遇到错误
错误: 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 '@gmail.com' at line 1
关于如何解决它的任何想法
答案 0 :(得分:1)
您需要将'
添加到email参数,更改
con.query("select * from people where Email_address= "+ req.body.email
到
con.query("select * from people where Email_address= '"+ req.body.email +"'"