After successfully inserting into the database, I am encountering an issue where this.lastID is undefined. Can anyone help me troubleshoot this code?
app.post('/products/create', (req,res) => {
upload(req, res, (err) => {
const name = req.body.name
const description = req.body.description
const Filename = req.file.filename
const id = this.lastID
console.log(id)
//console.log('Selected Files: ' + req.Filename);
db.uploadPost(name, description, Filename, function(error){
if(error){
console.log(err)
}
else{
console.log(this.lastID)
res.redirect('/products/'+id)
}
})
})
})
In addition, here is my database logic:
exports.uploadPost = function(name, description, Filename, callback){
const query = "INSERT INTO products('name', 'description', 'image') VALUES (?,?,?)"
const values = [name, description, Filename]
db.run(query,values, function(error){
callback(error)
})
}