0

I made a query like this:

INSERT INTO slider ('h1', 'h2', 'data-bg', 'data-img', 'data-url', 'status') VALUES ('Lalala', 'Lalala', 'http://localhost/mares.com.br-final/images/backgrounds/black_thumb.jpg', 'http://localhost/mares.com.br-final/images/banners/papeis_2015.png', 'http://lalala.com', 1)

But it's not working and phpMyAdmin says the syntax is incorrect.

So I tried adding a line through phpMyAdmin and it gave me back a query, I cleaned it, to take away some elements that I'm not inserting in my query, and tried it, and it works...

Here's the phpMyAdmin's query:

INSERT INTO slider (`data-img`, `data-bg`, `data-url`, `h1`, `h2`, `status`) VALUES ('images/lalal.jpg', 'images/back/lalala.jpg', 'http://lalal.com', 'Oi', 'Olá', '1')

Obs: I alredy tried to change ' for ` (the symbol to add code here) int he columns names.

The querys are identical to me, so why my query is wrong and phpMyAdmin's is not?

Marc Delisle
  • 8,879
  • 3
  • 29
  • 29
Rafael
  • 634
  • 1
  • 6
  • 13

1 Answers1

1

Your using single quotes for column which is wrong, instead of using single code for column use Backticks.

wrong syntax : ('h1', 'h2', 'data-bg', 'data-img', 'data-url', 'status')
right syntax : (`data-img`, `data-bg`, `data-url`, `h1`, `h2`, `status`)

for more refer the below link When to use single quotes, double quotes, and backticks in MySQL

Community
  • 1
  • 1
Ankur Tiwari
  • 2,762
  • 2
  • 23
  • 40