Reputation: 2126
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);
Upvotes: 0
Views: 71
Reputation: 89169
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);
Upvotes: 0
Reputation: 432210
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);
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);
Upvotes: 1