Skip to content
Advertisement

Why is my prepared statement causing this syntax error?

When I try to execute a query like this:

JavaScript

I get this error:

Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘ amount = ‘Et dolores et sunt quae officia aut voluptas asperiores optio id e…’ at line 1 in /home2-1/n/noorja/public_html/AdvancedTodoList/TodoTobuy.php:37 Stack trace: #0 /home2-1/n/noorja/public_html/AdvancedTodoList/TodoTobuy.php(37): PDOStatement->execute(Array) #1 {main} thrown in /home2-1/n/noorja/public_html/AdvancedTodoList/TodoTobuy.php on line 37

How can I fix the syntax error?

Advertisement

Answer

This WHERE clause doesn’t make sense:

JavaScript

It’s basically saying:

Where items, and where amount equals :items, and where :amount

I suspect you meant this:

JavaScript

Programming languages are not natural human languages. There’s no intuition and no room for ambiguity. On a WHERE clause you need each individual logical operation to be complete and need to combine them with logical operators (like AND or OR) into other complete operations.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement