I have two tables in MySQL workbench which are event and location. I'm trying to join both tables and extract the information from them based on user input. The problem is that I'm getting a MySQL syntax error and I don't know how to solve it.
app.get("/coordinates/:id", (req,res) =>{
console.log(req.params.id);
let sql = `SELECT Latitude, Longitude FROM event`
+ ` JOIN location ON location.EventID = event.Id`;
db.query(sql, (err,result) =>{
if(err){
console.log(err.message);
}
console.log(result)
res.status(200).json({
data: result
})
})
})
The following code works fine but I want instead of event.Id I want to substitute it with event.${req.params.id}, but 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 ':4' at line 1 and in all honesty I'm kinda lost as to what to do. Any help would be greatly appreciated!