Multiple Inserts

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
moiseszaragoza
Forum Commoner
Posts: 87
Joined: Sun Oct 03, 2004 4:04 pm
Location: Ft lauderdale
Contact:

Multiple Inserts

Post by moiseszaragoza »

I have been trying to inserts multiple records on a loop

but I am getting a error

Code: Select all

 
 
totalQuestions=10;
        $i=0;
        while ($i <= $totalQuestions-1):
            // GET VARS 
            $question_ID    = $_POST['question_ID'.$i];
            $answers        = $_POST['answers'.$i];
            
            
            // INSERT 
            $MySQL_InsertUsers = mysql_query("
            INSERT INTO UsersAnswers    (
                QuizID, UserID, question_ID, answers
            ) VALUES (
                '$Quiz_ID'  , '$UserID', '$question_ID', '$answers'
            )"
        , $ctech_con);
    
        
            
        $i++;
        endwhile;
 
 

ERROR

Error
SQL query:

INSERT INTO UsersAnswers( QuizID, UserID, question_ID, answers )
VALUES (

'17', '22', '24', '0'
)
INSERT INTO UsersAnswers( QuizID, UserID, question_ID, answers )
VALUES (
'17', '22', '23', '0'
)
INSERT INTO UsersAnswers( QuizID, UserID, question_ID, answers )
VALUES (
'17', '22', '20', '0'
)

MySQL said:

#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 'INSERT INTO UsersAnswers ( QuizID, UserID, question_ID, answers ) VALUES ( '17' ' at line 3



User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Multiple Inserts

Post by aceconcepts »

It doesn't seem to be accepting $UserId in the VALUES list. Where is this variable defined?
Post Reply