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?

2
  • I am using SET, not values. It works fine most other times and is valid syntax Commented Aug 1, 2018 at 13:51
  • How many columns are there in salon_client_prepaidCard? Commented Aug 1, 2018 at 14:08

2 Answers 2

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, ...); 
Sign up to request clarification or add additional context in comments.

Comments

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

6 Comments

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
I was in the process of updating the answer. I didn't see you were using SET.
@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
@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... stackoverflow.com/questions/861722/… 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
@Simrankaur I'm 100% sure they don't with this syntax. They'll be UPDATE statements: dev.mysql.com/doc/refman/8.0/en/set-statement.html
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.