It is inserting wrong numbers while using INSERT VALUES
<p>I have a problem with my INSERT VALUES. The problem is when I try and insert question numbers. Lets say I try to insert 2 questions. Well for first question the question number (QuestionId) should be 1 and for second question it should be 2.</p>

<p>But the problem is that both questions display question number 3 when I INSERT VALUES. So what it is doing for every question is inserting what would be the next question number which in this example is '3' for all questions.</p>

<p>Below is the example of what it is displaying at the moment when I echo $questionsql for 2 questions:</p>

<pre><code>INSERT INTO Question (QuestionId, QuestionContent) VALUES ('3','what is my name'), ('3','what is my age') 
</code></pre>

<p>The above is incorrect. Below is what it should of echoed:</p>

<pre><code>INSERT INTO Question (QuestionId, QuestionContent) VALUES ('1','what is my name'), ('2','what is my age') 
</code></pre>

<p>So what I want to know is how can I display the correct question numbers for each question,  it should add the correct question number in the correct order from question 1, 2 ,3 etc.</p>

<p>Below is the javascript code and form code where it appends a question into a table row. The user appends a question into a table row. When user adds first question it appends question number 1 and the question, when they append their second question it appends question number 2 and the question and etc.</p>

<pre><code>&lt;script&gt;

    function insertQuestion(form) {   

    var $tbody = $('#qandatbl &gt; tbody'); 
    var $tr = $("&lt;tr class='optionAndAnswer' align='center'&gt;&lt;/tr&gt;");
    var $qid = $("&lt;td class='qid'&gt;" + qnum + "&lt;/td&gt;");
    var $question = $("&lt;td class='question'&gt;&lt;/td&gt;");


    $('.questionTextArea').each( function() {

    var $this = $(this);
    var $questionText = $("&lt;textarea class='textAreaQuestion'&gt;&lt;/textarea&gt;").attr('name',$this.attr('name')+"[]")
                   .attr('value',$this.val())

    $question.append($questionText);

    });

    $tr.append($qid); 
    $tr.append($question);   
    $tbody.append($tr); 

    }

    ++qnum;
    $(".questionNum").text(qnum);
    $(".num_questions").val(qnum);

&lt;/script&gt;


&lt;form id="QandA" action="insertQuestion.php" method="post" &gt;

&lt;table id="question"&gt;
&lt;tr&gt;
    &lt;th colspan="2"&gt;
        Question Number &lt;span class="questionNum"&gt;1&lt;/span&gt;
        &lt;input type="hidden" class="num_questions" value="" name="numQuestion"&gt;
    &lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;td rowspan="3"&gt;Question:&lt;/td&gt; 
    &lt;td rowspan="3"&gt;
        &lt;textarea class="questionTextArea" rows="5" cols="40" name="questionText"&gt;&lt;/textarea&gt;
    &lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;

&lt;/form&gt;
</code></pre>

<p>Below is the php code where it INSERT VALUES.</p>

<pre><code>$i = 0;

$insertquestion = array();

for($i = 0; $i++ ){

   $insertquestion[] = "'".  mysql_real_escape_string( $_POST['numQuestion'] ) ."','".  
                    mysql_real_escape_string( $_POST['questionText'][$i] ) ."'";

}

 $questionsql = "INSERT INTO Question (QuestionId, QuestionContent) 
    VALUES (" . implode('), (', $insertquestion) . ")";

    echo($questionsql);
</code></pre>
