manzwebdesigns

PDO Insert statement

Jun 18th, 2013
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.11 KB | None | 0 0
  1.     $sql = <<<EOD
  2. INSERT INTO `downloads` (`download_id`, `user_name`, `ip_address`, `download_date`, `comment`, `Referring_URL`, `HTTP_Agent`, `email`, `download_dir`, `file_id`)
  3. VALUES (NULL, :visitor, :ip, :myDate, :notes, :httpref, :httpagent, :visitormail, :dl_dir, :attn);
  4. EOD;
  5.  
  6.     $db = new MySQL();
  7.     $res = $db->prepare($sql);
  8.     $res->execute(
  9.         array(
  10.             ':visitor' => $visitor,
  11.             ':ip' => $ip,
  12.             ':myDate' => $myDate,
  13.             ':notes' => $notes,
  14.             ':httpref' => $httpref,
  15.             ':httpagent' => $httpagent,
  16.             ':visitormail' => $visitormail,
  17.             ':dl_dir' => $dl_dir,
  18.             ':attn' => $attn
  19.         )
  20.     );
  21.     $rescnt = $res->rowCount();
  22.  
  23. // error message: PHP Fatal error:  Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''ZH'')' at line 2'
  24.  
  25. // EDIT: I removed the apostrophe after :attn in the sql statement... now works!
Advertisement
Add Comment
Please, Sign In to add comment