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.

2
  • change your prepare query to this $stmt = $conn->prepare("UPDATE diensten SET titel = :titel, content = :beschrijving, img = :img WHERE id = :id"); Commented Mar 20, 2017 at 13:57
  • I reopened the duplicate (stackoverflow.com/questions/11321491/…) 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). Commented Mar 20, 2017 at 14:00

1 Answer 1

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.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.