如何使下面的代码不容易受到SQL注入攻击?并且还能够接受参数中的“和”字符?
app.get('/addStudent',(req,res) => {
const {fname, lname, othname, bloodType}= req.query;
let sqlstmt = "INSERT INTO `students` (`fname`, `lname`, `othname`, `bloodtype`) VALUES ('"+fname+"', '"+lname+"', '"+othname+"', '"+bloodType+"')"
db.query(sqlstmt,(err,result) => {
if(err){console.log('Error occured while fetching user information',err)}
console.log(result);
res.send(result);
});
});发布于 2020-03-27 14:36:12
对于您选择的DBMS,您应该使用驱动程序包支持的准备好的语句。
MySQL的一个例子:https://github.com/mysqljs/mysql#preparing-queries
https://stackoverflow.com/questions/60881018
复制相似问题