我正在尝试使用快速表单中的数据将行发布到mysql数据库中,但始终会出现SQL语法错误
router.post('/add', function(req, res, next) {
var title = req.body['title'];
var director = req.body['director'];
var release = req.body['release'];
var review = req.body['review'];
connection.query("INSERT INTO films.filmStore (title, director, review, release) VALUES ('" + title.toString() + "', '" + director.toString() + "', '" + review.toString() + "', '" + release.toString() + "');", function(err, result){
if(err) throw err;
console.log("1 record inserted");
});
res.redirect('/');
});
但是我得到一个错误
throw err; // Rethrow non-MySQL errors
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 'release) VALUES ('Superman', 'Richard Donner', 'One of the best films of all tim' at line 1
我已经尝试了所有可以想到的方法,但是我对SQL还是陌生的,无法弄清与我所见过的其他示例有何不同。
答案 0 :(得分:0)
release
是mysql中的保留关键字。
参见:https://dev.mysql.com/doc/refman/8.0/en/keywords.html
要么更改该列的名称,要么使用反引号:
"INSERT INTO films.filmStore (title, director, review, `release`) VALUES (..."