Page 1 of 1

Multiple Inserts

Posted: Mon Nov 24, 2008 10:20 pm
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




Re: Multiple Inserts

Posted: Tue Nov 25, 2008 4:39 am
by aceconcepts
It doesn't seem to be accepting $UserId in the VALUES list. Where is this variable defined?