-1

This is my php code

 $update = [
    'colour' => $colour     
  ];
  
  $sql = "UPDATE colours SET colour=:colour WHERE colour=:colour";
  $stmt= $db->prepare($sql);
  $stmt->execute($update);

all my queries work but when I update a table with value where the value is the same it does not update. Should be an easy one for someone familiar with this problem. All help appreciated. thank you

gabrielkolbe
  • 145
  • 9

1 Answers1

0

According to the docs at https://www.php.net/manual/en/pdo.prepare.php :

You cannot use a named parameter marker of the same name more than once in a prepared statement, unless emulation mode is on.

It appears you need to add the following to make that query work :

$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, TRUE);

Info found from : Use bound parameter multiple times

Marshall C
  • 359
  • 3
  • 8
  • I did not downvote, but I can guess that some people downvote a legitimate answer if the question is a duplicate. I've been chastised for doing that in the past. – Bill Karwin Jun 08 '22 at 20:48
  • 1
    Thanks for that. I didn't even know where to start searching for this answer.. – gabrielkolbe Jun 09 '22 at 17:04