mysql - post call is not working in node js -


i trying perform post call in node js, testing through post not able retrive data, node code,

 exports.login = function( req, res ) {  console.log("params:"+req.body.email);   //console.log('email:'+params.email);  connection.query('select * profile 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 getting fail , error is

{ [error: er_parse_error: have error in sql syntax; check manual corresponds mysql server version right syntax use near '@gmail.com' @ line 1] 

my input through postman

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

don't build query string directly, leaves open injection attacks , chokes on characters, experiencing here. use placeholder so:

var query = "select * profile email = ?";  connection.query(query, [req.body.email], function(error,result,rows,fields) { ... 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -