2

when I run the function that includes this code I get null returned. Can anybody see my issue?

$statement = $connect->prepare("UPDATE pages " . 
"SET " . 
"pageTitle = :pageTitle, " . 
"pageSubTitle = :pageSubTitle, " . 
"pageContent = :pageContent, " . 
"pageMetaKeywords = :pageMetaKeywords, " . 
"pageMetaDescription = :pageMetaDescription, " . 
"pageDateUpdated = :pageDateUpdated " . 
"WHERE " . 
"pageID = :pageID");

$array = array(
   "pageTitle" => $_POST["pageTitle"],
   "pageSubTitle" => $_POST["pageSubTitle"],
   "pageContent" => $_POST["pageTitle"],
   "pageMetaKeywords" => $_POST["pageContent"],
   "pageMetaDescription" => $_POST["pageMetaDescription"],
   "pageDateUpdated" => $_POST["pageDateUpdated"],
   "pageID" => $_POST["pageID"]
);

$result = $statement->execute($array);
  • you really should look into using [HEREDOC](http://php.net/heredoc)s if you're going to be doing multi-line string assignments. Far less opportunity for error and far more readable in the long run. – Marc B Jun 17 '13 at 15:40
  • Ok, thank you for that advice. I haven't come across HEREDOCs before and will look into right now – Darren Parker Jun 17 '13 at 15:44
  • Nothing to look into actually. heredoc is worse than regular strings. – Your Common Sense Jun 17 '13 at 16:33
  • instead of "seeing" into code one have to *debug* it. [PDO query fails but I can't see any errors. How to get an error message from PDO?](http://stackoverflow.com/a/15990858/285587). And only **after** you get a **certain** error message, start for fixing. This colon from the accepted answer cannot be an issue, by the way. – Your Common Sense Jun 17 '13 at 16:34

1 Answers1

4

The parameters you're passing in via the array are incorrect. You need to prefix them with : as well:

$array = array(
   ":pageTitle" => $_POST["pageTitle"],
    ^--- required
Marc B
  • 356,200
  • 43
  • 426
  • 500