Keep data out of SQL text

Take your time, follow the code and check your understanding.

The codePostgreSQL queries
const sql = "SELECT * FROM products WHERE title = '" + title + "'";
Your answer4 min · no timer
What needs fixing?

Show solution and explanation

Parameterised queries keep user values separate from SQL syntax. String concatenation can turn a value into executable SQL.

Use a parameterised query with a $1 placeholder and a separate values array.