0

I've been at this for a while now, and i'm having some trouble with my sql. Recently i've learned a bit about prepared statements and i've been using them untill this without any trouble. However now i'm having the issue that i'm not getting errors when i manually transfer the coded query into phpmyadmin, but when i excecute the code from the server it's not updating any records whatsoever.

excecuted code:

$stmt = $conn->prepare("UPDATE `diensten` SET `titel` = ':titel', `content` = ':beschrijving', `img` = ':img' WHERE `diensten`.`id` = ':id'");
  $stmt->execute(array(':title' => $titel, ':beschrijving' => $beschrijving, ':img' => $img, ':id' => $id));

excuse the dutch in the code although it shouldn't obstruct any functionality.

Chris
  • 4,672
  • 13
  • 52
  • 93
  • change your prepare query to this `$stmt = $conn->prepare("UPDATE diensten SET titel = :titel, content = :beschrijving, img = :img WHERE id = :id");` – Mario Mar 20 '17 at 13:57
  • I reopened the duplicate (http://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-backticks-in-mysql) because that was generic about different types of quotes. The problem here is specifically about type handling with parameters, so that answer is not focused on this particular problem (the excellent accepted answer does cover it, but it is a bit far down and uses prepared statements in MySQL rather than through an application language). – Gordon Linoff Mar 20 '17 at 14:00

1 Answers1

2

When you use prepared statements, you do not need single quotes around the values. The type is handled by the parameter insertion. So, you simply need:

$stmt = $conn->prepare("
UPDATE `diensten`
    SET `titel` = :titel,
        `content` = :beschrijving,
        `img` = :img
WHERE `diensten`.`id` = :id");

(I put this on multiple lines for readability.)

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786