【发布时间】:2014-11-07 10:13:58
【问题描述】:
我有一个NodeJS 应用程序,我想使用sequelize()-方法将表单中的一些数据插入到我的MySQL-数据库的表中。
这是我的表格
<form id="addVideo" method="post">
<input type="url" name="video_url" required></input>
<input type="hidden" value="" name="artist_id"></input>
<input type="hidden" value="youtube" name="type"></input>
</form>
我的帖子功能:
$('form#addVideo').submit(function(e){
e.preventDefault();
var form = $(this);
var jsonvideoFormData = utils.serializeToJSON(form);
var xhrData = _.pick(jsonvideoFormData, 'video_url', 'artist_id', 'type');
api.post('/videos', xhrData, function(response){
alert('Video has been added!');
});
});
那么后端代码是这样的:
exports.addVideo = function(req, res, next){
var videoURL = req.body.video_url;
var artistId = req.body.artist_id;
var type = req.body.type;
db.sequelize.query('INSERT INTO social_urls (artist_id,urls,type) VALUES('artistId','videoURL','type')', function(err) {
if(err){
return res.json(400, {response: {code: 400, message:'An error appeared.'}});
} else{
console.log('succes');
res.json(201, {response: {code: 201, message: 'Video has been added'}});
}
});
}
但由于某种原因,我不知道这不起作用。谁能帮帮我?
非常感谢!!
【问题讨论】:
-
不工作?你能说得更具体点吗?
-
我不是 sequelize 方面的专家,但我看到那里的代码容易发生 SQL 注入。
标签: javascript mysql node.js