0

I'm getting this error:

#1064 - 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 'VALUES (1039,200,'2',NULL,NULL,NULL,'cash',NULL,1)' at line 1

for this query:

INSERT INTO anu_donations (projectid,donation_amount,donated_by,donated_by_uid,donation_details, comments,payment_medium,donor_comments,created_by)

VALUES (1039,100,'1',NULL,NULL,NULL,'cash',NULL,1), VALUES (1039,200,'2',NULL,NULL,NULL,'cash',NULL,1);

enter image description here

2 Answers 2

1

You only need VALUES once

INSERT INTO anu_donations    
(projectid,donation_amount,donated_by,donated_by_uid,donation_details, 
comments,payment_medium,donor_comments,created_by)

VALUES 
   (1039,100,'1',NULL,NULL,NULL,'cash',NULL,1), 
   (1039,200,'2',NULL,NULL,NULL,'cash',NULL,1);

See INSERT in the MySQL docs:

INSERT statements that use VALUES syntax can insert multiple rows. To do this, include multiple lists of column values, each enclosed within parentheses and separated by commas. Example:

INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);
Sign up to request clarification or add additional context in comments.

Comments

0

The SQL Statement for INSERT Syntax is as follows:

INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
    [INTO] tbl_name [(col_name,...)]
    {VALUES | VALUE} ({expr | DEFAULT},...),(...),...
    [ ON DUPLICATE KEY UPDATE
      col_name=expr
        [, col_name=expr] ... ]

Thus, you can see that VALUES is used once. Thus, you need to change your SQL as follows:

INSERT INTO anu_donations (projectid,donation_amount,donated_by,donated_by_uid,donation_details, comments,payment_medium,donor_comments,created_by)

VALUES (1039,100,'1',NULL,NULL,NULL,'cash',NULL,1), (1039,200,'2',NULL,NULL,NULL,'cash',NULL,1);

Comments

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.