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?

Recommended Answers

All 9 Replies

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')

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'

What happens if you remove the back ticks on just the download-url column?

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

Fixed the problem, was a spelling error.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.