Barry Hamilton
Barry Hamilton

Reputation: 973

what is wrong with my pdo syntax?

I'm trying to execute a pdo update statement definded as follows:

 $sql = "UPDATE users SET (email,name) VALUES (:email,:name) WHERE userId = :userId";
 $result= $db->prepare($sql);
 $result->execute(array(':userId'=>21,':email'=>'test',':name'=>'testname'));

But no matter what I try it returns the following error

Uncaught exception 'PDOException' with message '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 '(email,name) VALUES ('test','testname') WHERE userId = '21'' at line 1' in /var/www/vhosts/tftest.co.uk/biggreensquare.co.uk/application/models/user_model.php:79

I can't see what is wrong with my syntax that is causing this any feedback much appreciated.

Upvotes: 1

Views: 40

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269753

I would expect the syntax to look like:

UPDATE users
    SET email = :email,
        name = :name
    WHERE userId = :userId;

Upvotes: 3

Related Questions