In the SQL query where city clause when I put string ‘delhi’ I get results but when I put a variable like below I get error unknown column delhi in where clause. how to solve the issue?
router.get('/filter/:city', (req, res) => {
const location = req.params.city;
const singleQuoteLocation = location.replace(/"/g, "'");
connection.query(
`select * from weather_data where city=${singleQuoteLocation}`,
(err, results, field) => {
if (err) {
console.log(err);
} else {
res.status(200).send(results);
console.log(results);
}
}
);
});