2011-12-29 4 views
0

Je reçois cette erreur:erreur de requête MySQL pour ma requête

#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

pour cette requête:

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

Répondre

1

Vous avez seulement besoin VALUES une fois

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

S ee 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); 
0

L'instruction SQL pour INSERT Syntax est la suivante:

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] ... ] 

Ainsi, vous pouvez voir que VALUES est utilisé une fois. Ainsi, vous devez modifier votre SQL comme suit:

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