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?

Re: Sql Statement Issues 80 80

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')
Re: Sql Statement Issues 80 80

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

Re: Sql Statement Issues 80 80

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.

Re: Sql Statement Issues 80 80

I'm now getting the error

Unknown column 'download-url' in 'field list'
Re: Sql Statement Issues 80 80

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

Re: Sql Statement Issues 80 80

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'
Re: Sql Statement Issues 80 80

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

Re: Sql Statement Issues 80 80

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

Re: Sql Statement Issues 80 80

Fixed the problem, was a spelling error.

Be a part of the DaniWeb community

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