0
INSERT INTO salon_client_prepaidCard SET (\'010818-demo-1\', 4, 5, 1, 6000) 

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 \'(\'010818-demo-1\', 4, 5, 1, 6000)\' at line 1', sqlState: '42000', index: 0, sql:

The table has an id field that is auto-increment. What looks wrong here?

ADyson
  • 57,178
  • 14
  • 51
  • 63
systemdebt
  • 4,589
  • 10
  • 55
  • 116

2 Answers2

4

the correct syntax for mysql inserts is;-

INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...); 

or using set;-

INSERT INTO table_name
   SET column1 = 'value1',
       column2 = 'value2',
       column3 = 'value3';

If you are adding values for all the columns of the table, you do not need to specify the column names in the SQL query;-

INSERT INTO table_name
VALUES (value1, value2, value3, ...); 
Clint
  • 973
  • 7
  • 18
1

Why are you escaping quotes? Also, VALUES should be used instead of SET.

INSERT INTO salon_client_prepaidCard VALUES ('010818-demo-1', 4, 5, 1, 6000);
BenM
  • 52,573
  • 26
  • 113
  • 168
  • Still does not work. I get 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 '('010818-demo-1', 4, 5, 1, 6000)' at line 1 with the insert statement you wrote – systemdebt Aug 01 '18 at 13:50
  • I was in the process of updating the answer. I didn't see you were using `SET`. – BenM Aug 01 '18 at 13:51
  • 1
    @MadhurBhaiya Not true: *If you are adding values for all the columns of the table, you do not need to specify the column names in the SQL query. However, make sure the order of the values is in the same order as the columns in the table. The INSERT INTO syntax would be as follows* – BenM Aug 01 '18 at 13:51
  • But what's wrong with using set? my other insert statements work just fine with SET – systemdebt Aug 01 '18 at 13:52
  • 1
    @Simrankaur "my other insert statements work just fine with SET " I doubt it...are you sure they weren't UPDATE statements? Or just possibly it could be as per the example here, which seems to be a mysql-specific extension... https://stackoverflow.com/questions/861722/mysql-insert-into-table-values-vs-insert-into-table-set in which case you'd need the x=1,y=2 syntax for the fields, not a bracketed list. You can't mix the two styles as you were doing – ADyson Aug 01 '18 at 13:52
  • 1
    @Simrankaur I'm 100% sure they don't with this syntax. They'll be `UPDATE` statements: https://dev.mysql.com/doc/refman/8.0/en/set-statement.html – BenM Aug 01 '18 at 13:53