2
I have the following route that is responsible for receiving the data coming from a form and doing an update of the data that is in my database
router.post('/articles/update', (req, res) => {
let id = req.body.id;
let title = req.body.title;
let body = req.body.body;
let category = req.body.category;
Article.update({title: title, body: body, categoryId: category, slug: slugify(title)}, {
where: {
id: id,
}
}).then(() => {
res.redirect('/admin/articles');
}).catch((error) => {
console.log('Error' + error)
});
})
When the route is executed, all actions are carried out including I am redirected to the admin/Articles page (falls in Then once the function has returned success) but the data is not changed in the database. Why?
In the code posted there is no error at all, so much so that is executed the then(), probably the error is elsewhere. Unless the values are not in agreement. You have already given a
log
these values of the variables there to see, mainly the variableid
?– LeAndrade
Because it’s expensive!! I went there and in fact that’s where the problem is, the id (req.body.id) is returning empty. Now is to find out the reason, since the name of the form where I send the ID is exactly the one I get on my route. But this has saved enough, thanks man! D
– Mateus Cavalcanti