I am getting this error while I am trying to send a put request to update a row of a product table in mysql using nodejs. Here's my code:
exports.updateProduct=(req,res)=>{
const productId=req.params.productId;
const keys=Object.keys(req.body);
const data=keys.map(e=>{
const value=e+'='+req.body[e];
return value
})
const sql='update product set ? where productId=?';
connectDB.query(sql,[data,productId],(err,result)=>{
if(err){
res.status(400).json({
status:'failed',
message:err.message
})
}
else{
res.status(200).json({
status:'success',
message:result
})
}
})
}
while I am trying to send request using postman I'm getting this 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 ''productTitle=accha product' where productId='19'' at line 1"