I'm working on a side project and have hit a bit of a dead end when coming across this error. I've ascertained that it's originating from node-postgres package somewhere, but I see nothing inherently wrong with my query!
Here's my code:
router.post("/product/:id", async (req, res) => {
const id = req.params.id;
if (!id) throw new Error("ID not present");
if (!validateProductReviewForm(req.body))
throw new Error("Form not valid. Please fix and try again");
const { name, email, rating, comment } = req.body;
const date = new Date();
const sqlText = `INSERT INTO reviews ("name", email, rating, comment, date, productid) VALUES (${name}, ${email}, ${rating}, ${comment}, ${date}, ${id})`;
console.log(sqlText);
const { rows } = await query(sqlText);
res.send(rows);
});
And here is my logged query:
INSERT INTO reviews ("name", email, rating, comment, date, productid) VALUES (Bill, [email protected], 2, testing a review post, Tue Mar 30 2021 17:59:22 GMT+0100 (British Summer Time), 2)
Any help would be much appreciated. Many thanks