Skip to content
Advertisement

How do I write UPDATE for SQL in php

I have tried everything I can think of and still get the following error when I try to run this. I’m thinking it’s a minor mistake since I spliced and diced this code from other places but for the sake of me, I can’t seem to figure it out.

Fatal error: Uncaught Exception: 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 ‘[‘ADPs’],owner=[”],type=[”],company=[”],status=[‘Active’],soc=[‘yes’],email=[‘ at line 1 in C:xampphtdocsupdateVendor.php:129 Stack trace: #0 C:xampphtdocsupdateVendor.php(129): PDOStatement->execute() #1 {main} in C:xampphtdocsupdateVendor.php:136 Stack trace: #0 {main} thrown in C:xampphtdocsupdateVendor.php on line 136

I’m thinking my syntax is totally wrong or I misplaced something but I’ve been staring at this for so long, that I don’t see my error.

Advertisement

Answer

Please, read PDO docs, first.

Especially part with prepare method.

Here, in example, you can see, that all values are presented as pseudo-variables with ‘?’, and then are inserted in accordance with the order in the request.

So, in prepare method insert your query, like this:

And in execute method bind params:

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