Newbie Question: PDO and MYSQL INSERT Query problem?

Are you sure of the table name is 404s it sound like an incorrect identifier INSERT INTO 404s (dateTime, referer, page, ip, host, ua) value (:dateTime, :referer, :page, :ip, :host, :ua) Try : INSERT INTO `404s` (dateTime, referer, page, ip, host, ua) value (:dateTime, :referer, :page, :ip, :host, :ua) Use backquote around `404s` Note Keep in mind that construct such as : create table `404` ( `33` integer) Are valid When you build complex request use of ` is very useful to avoid some kind of painful SQL errors especially when you format request from an introspection algorithm Like table, columns and database have to be protected.

Are you sure of the table name is 404s it sound like an incorrect identifier. INSERT INTO 404s (dateTime, referer, page, ip, host, ua) value (:dateTime, :referer, :page, :ip, :host, :ua) Try : INSERT INTO `404s` (dateTime, referer, page, ip, host, ua) value (:dateTime, :referer, :page, :ip, :host, :ua) Use backquote around `404s` Note Keep in mind that construct such as : create table `404` ( `33` integer); Are valid . When you build complex request use of ` is very useful to avoid some kind of painful SQL errors especially when you format request from an introspection algorithm.

Like table, columns and database have to be protected.

Was wondering that too. To my surprise Mysql accepts such silly table names without backticks. (Certainly not standard SQL compliant anyway..) – mario Jun 15 at 12:29 And try columns name – VGE Jun 15 at 12:30 @mario I can't seem to write the backquotes in this comment, but anyway I have tried doing this and it hasn't made any difference.

– baritoneuk Jun 15 at 12:31 @VGE - what do you mean by columns name? – baritoneuk Jun 15 at 12:32 Mario, my level of mysql does not accept request without backticks for identifier like 404s. – VGE Jun 15 at 12:46.

In addition to @Dave Kiss, the SQL statement has a small typo at 'value'. It should be 'VALUES'. INSERT INTO 404s (dateTime, referer, page, ip, host, ua) VALUES (:dateTime, :referer, :page, :ip, :host, :ua) Maybe that is all.

BTW: Using leading numbers in identifiers (like your table name 404s) is bad style. You may use them, but you have to but the table name in backticks: INSERT INTO `404s` (dateTime, referer, page, ip, host, ua) VALUES (:dateTime, :referer, :page, :ip, :host, :ua) Resources: dev.mysql.com/doc/refman/5.6/en/insert.html dev.mysql.com/doc/refman/5.6/en/identifi....

1 It works with VALUE or VALUES as far as I can tell. – baritoneuk Jun 15 at 13:48.

Try adding the colons to your keys in the data array. /* Execute a prepared statement by passing an array of insert values */ $data = array( ':dateTime' => $_dtNow, ':referer' => $_referer, ':page' => $_thisPage, ':ip' => $_ip, ':host' => $_host, ':ua' => $_ua ); $statement = $db->prepare("INSERT INTO 404s (dateTime, referer, page, ip, host, ua) value (:dateTime, :referer, :page, :ip, :host, :ua)"); $statement->execute($data).

I hadn't seen that in the examples in the articles I read. In any case this hasn't worked. – baritoneuk Jun 15 at 12:35.

I'm attempting to be more secure and start using PDO and prepared statements. I've hit a brick wall and I can't understand why the following doesn't work. I am trying to insert a row (to log a 404 error).

I have read up about named and unnamed placeholders and I think the named placeholder method will be easier to maintain. I've also tried using "try" and "catch" for the first time.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions