I have a NodeJS app and I want to insert some data from a form into a table of my MySQL-database by using the sequelize()-method.
So here is my form
<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>
My post function:
$('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!');
});
});
Then the backend code looks like this:
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'}});
}
});
}
But for some reason I do not know this is not working. Can anyone help me out?
Many thanks!!