-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
  • 26,923
  • 21
  • 73
  • 125

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,172
  • 7
  • 41
  • 75
2

by is a reserved keyword. Try:

INSERT INTO downloads_log 
(`file`, `by`, `time`) VALUES
(1, 1, NOW())
Kevin Robatel
  • 7,570
  • 3
  • 41
  • 56
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())