I'm trying to find the errors in this sql statement

INSERT INTO images(user, server, img-name, download, download-url, image-loc) VALUES(test@test.com, 3, Penguins.jpg, no, GaNfT, 69Z8PwE0uJLfRNDijPenguins.jpg)

I also have an auto increment column but as I understand it you shoudln't supply a value

It comes out with this 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 '-name, download, download-url, image-loc) VALUES(test@test.com, 3, Penguin' at line 1

I have no idea what the error is, can anybody help?

5 Years
Discussion Span
Last Post by fheppell

User is a reserved name

INSERT INTO images (`user`, `server`, `img-name`, `download`, `download-url`, `image-loc`) VALUES ('test@test.com', '3', 'Penguins.jpg', 'no', 'GaNfT', '69Z8PwE0uJLfRNDijPenguins.jpg')

Edited by pixelsoul


Okay, thanks. Does the number, in this case 3 need to be in quotes because the field is an integer?


I updated that snippet. Accidently wrapped the table names in single quotes rather than back ticks.

Yes, I would just wrap all of the values in single quotes.


I'm now getting the error

Unknown column 'download-url' in 'field list'

Make sure you are using back ticks around the column names and not single quotes. Single quotes should only be around the values.


Definatley got the right quotes and backticks

INSERT INTO images (`username`, `server`, `img-name`, `download`, `download-url`, `image-loc`) VALUES ('test@test.com', '1', 'Penguins.jpg', 'yes', 'LA97o', '53YvDgA5xGOTEw3kuPenguins.jpg')
Unknown column 'download-url' in 'field list'

fheppell- show your table structure.Because as per error there is no coloumn with name download-url.
Make sure you are writing correct spelling as mentioned in table

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.