简体   繁体   English

POST调用在Node JS中不起作用

[英]post call is not working in node js

I am trying to perform a post call in node js, i am testing it through post but i am not able to retrive data, my node code, 我正在尝试在节点js中执行发布调用,我正在通过发布对其进行测试,但是我无法检索数据,我的节点代码,

 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);
    }
  // }

  });}

my routes, 我的路线

 router.post('/login',cors(), admin.login);

i am getting fail and my error is 我越来越失败,我的错误是

{ [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]

my input through postman 我通过邮递员的输入

{"email":"s@gmail.com"}

Don't build the query string directly, this leaves you open to injection attacks and also chokes on certain characters, as you are experiencing here. 不要直接构建查询字符串,这会使您容易受到注入攻击,并且在遇到某些字符时也会感到窒息。 Use a placeholder like so: 使用占位符,如下所示:

var query = "select * from profile where email = ?";

connection.query(query, [req.body.email], function(error,result,rows,fields) {
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM