manzwebdesigns icon

PDO Insert statement

manzwebdesigns | PRO | 06/18/13 07:03:00 PM UTC | 0 ⭐ | 204 👁️ | Never ⏰ | []
PHP |

1.11 KB

|

None

|

0 👍

/

0 👎

    $sql = <<<EOD
INSERT INTO `downloads` (`download_id`, `user_name`, `ip_address`, `download_date`, `comment`, `Referring_URL`, `HTTP_Agent`, `email`, `download_dir`, `file_id`)
VALUES (NULL, :visitor, :ip, :myDate, :notes, :httpref, :httpagent, :visitormail, :dl_dir, :attn);
EOD;
 
    $db = new MySQL();
    $res = $db->prepare($sql);
    $res->execute(
        array(
            ':visitor' => $visitor,
            ':ip' => $ip,
            ':myDate' => $myDate,
            ':notes' => $notes,
            ':httpref' => $httpref,
            ':httpagent' => $httpagent,
            ':visitormail' => $visitormail,
            ':dl_dir' => $dl_dir,
            ':attn' => $attn
        )
    );
    $rescnt = $res->rowCount();
 
// 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'
 
// EDIT: I removed the apostrophe after :attn in the sql statement... now works!

Comments