Why can't I insert this into MySQL?

mysql

Solution

The error tells you that the error happens at the text `key`, and it's quite correct: `key` is a reserved word in MySQL.

Where you use it as a field name, you must enclose it in backticks (`); it's a good general practice anyway.

So:

INSERT INTO `filez` (
  `filename`,
  `uploadedby`,
  `dateuploaded`,
  `public`,
  `FileSize`,
  `FileTransferSize`,
  `key`,
  `bytes`
)
VALUES(
  'tommy3244/tesABCscdsdasdasdD.testtest',
  'tommy3244',
  '%27 %December %2012, %7:%32:%15%AM',
  1,
  7,
  7,
  '`',
  'TestDoc'
)

Problem

I probably made a stupid error on my syntax for the query, but I can't seam to fix it. Here is the query my program tries to execute: ``` INSERT INTO filez ( filename, uploadedby, dateuploaded, public, FileSize, FileTransferSize, key, bytes ) VALUES( 'tacct/tesABCscdsdasdasdD.testtest', 'tacct', '%27 %December %2012, %7:%32:%15%AM', 1, 7, 7, '`', 'TestDoc' ) ``` And here's the mysql_error: 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 'key, bytes) VALUES('tacct/tesABCscdsdasdasdD.testtest', 'tacct', '%27 %D' at line 1 I did `mysql_real_escape_string()` on EVERYTHING except the FileSize and FileTransferSize in the query. Could you tell me what I am doing wrong? Thanks!

Original source

Related problems