-1

Hey i have an error in my mysql syntax, and i dont know why i get it. I can't see an error in my code and i have checked the web for help...

    INSERT INTO downloads_log 
    (file,by,time) VALUES
    (1,1, NOW())

The error:

'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 'by, time) VALUES (1,1,NOW())
Dharman
  • 30,962
  • 25
  • 85
  • 135
BenjaBob
  • 29
  • 7

3 Answers3

2

by,file and time are reserved keywords used in MYSQL. Use a back tick (`) to escape the keywords in your query. Change your query to :

INSERT INTO downloads_log 
    (`file`,`by`,`time`) VALUES
    (1,1, NOW())
Jenz
  • 8,280
  • 7
  • 44
  • 77
2

by is a reserved keyword. Try:

INSERT INTO downloads_log 
(`file`, `by`, `time`) VALUES
(1, 1, NOW())
Kevin Robatel
  • 8,025
  • 3
  • 44
  • 57
1

You're using reserved keywords as column names. Try to avoid using reserved keywords as column names, but if you haven't choice you have to pass them to backticks `` in following:

INSERT INTO downloads_log (`file`,`by`,`time`) VALUES (1,1, NOW())