我正在尝试在node js中执行post调用,我正在通过post测试它,但我无法检索数据, 我的 Node 代码,
exports.login = function( req, res ) {
console.log("Params:"+req.body.email);
//console.log('email:'+params.email);
connection.query('SELECT * FROM profile where email ='+req.body.email,function(error,result,rows,fields){
if(!!error){console.log(error)
console.log('fail');
}else{
console.log(result);
res.send(result);
}
// }
});}
我的路线,
router.post('/login',cors(), admin.login);
我失败了,我的错误是
{ [Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@gmail.com' at line 1]
我通过 postman 输入
{"email":"s@gmail.com"}
最佳答案
不要直接构建查询字符串,这会让您容易受到注入(inject)攻击,并且还会阻塞某些字符,正如您在这里所经历的那样。使用如下占位符:
var query = "select * from profile where email = ?";
connection.query(query, [req.body.email], function(error,result,rows,fields) {
...
关于mysql - 后调用在 Node js 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39462488/