I’m trying to update my database table with PDO, but to avoid security leaks, I’m using parameters in my query.
I’m getting this error:
exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: parameter was not defined' in D:\xampp\htdocs\logansarchive\admin\do.article.php:25 Stack trace: #0 D:\xampp\htdocs\logansarchive\admin\do.article.php(25): PDOStatement->execute() #1 {main}
Here’s my code:
$sql = "update articles set".
"category = :cat,".
"articletitle = :title,".
"articlecontent = :content".
"where articleid = :target";
$result = $dbh->prepare($sql);
$result->bindParam(":cat", $category);
$result->bindParam(":title", $title);
$result->bindParam(":content", $content);
$result->bindParam(":target", $target);
$result->execute();
I found this Not able to update rows using PDO
which looks fairly similar to what I’m doing, but I’m not sure how to fix my code based on this as I can’t see any of the problems listed there by the guy who answered that question.
Any help will be greatly appreciated.
Thanks for your time!
our both codes are correct but the sql statement has two little errors. if you echo your sql then you can see that you forget two whitespaces … one in line one after set “update articles set ” and the second in line 4 after :content “articlecontent = :content ” … now it should work!