title: Insert in for loop is not working accordingly in PHP
body: <p>Currently im developing a module for admin to create their own questions &amp; answers for student exams. Admin just fill the input and saved. Admin can add questions as many as he click the 'Add Question' button. Unfortunately the insert code here is not working as expected. Below is some of the part that im working on.</p>
  <p>Table :</p>
  <pre><code>CREATE TABLE `questions` (
    `question_id` bigint(5) NOT NULL AUTO_INCREMENT,
    `exam_id` bigint(5) DEFAULT NULL,
    `text` varchar(250) DEFAULT NULL,
    `question_no` int(10) DEFAULT NULL,
    `choices` varchar(200) DEFAULT NULL,
    PRIMARY KEY (`question_id`)
  ) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=latin1
  </code></pre>
  <p>PHP code :</p>
  <pre><code>&lt;?php
  
  include('includes/dbconnection.php');
  
  if(isset($_POST['submit']))
    { for($i=0; $i&lt;count($_POST['answer']); $i++) {
               $question = $_POST['question'][$i];
               $noquestion = $_POST['noquestion'][$i];
               $answer = $_POST['answer'][$i];    
               $query = mysqli_query($con,&quot;INSERT INTO questions (text,question_no,choices) VALUES ('$question','$noquestion','$answer')&quot;);
      }
      echo &quot;&lt;script&gt;alert('Save Successfull!');&lt;/script&gt;&quot;;
  }
    ?&gt;
  
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta charset=&quot;utf-8&quot;&gt;
      &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;
      &lt;title&gt;ABMS&lt;/title&gt;
      &lt;link rel=&quot;icon&quot; href=&quot;favicon.png&quot;&gt;
      &lt;link href=&quot;css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot;&gt;
      &lt;link href=&quot;css/font-awesome.min.css&quot; rel=&quot;stylesheet&quot;&gt;
      &lt;link href=&quot;css/styles.css&quot; rel=&quot;stylesheet&quot;&gt;
      &lt;link rel=&quot;stylesheet&quot; href=&quot;http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/base/jquery-ui.css&quot; type=&quot;text/css&quot; media=&quot;all&quot;&gt;
      &lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js&quot;&gt;&lt;/script&gt;
      &lt;script type=&quot;text/javascript&quot; src=&quot;https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/jquery-ui.min.js&quot;&gt;&lt;/script&gt;
   
      &lt;!--Custom Font--&gt;
      &lt;link href=&quot;https://fonts.googleapis.com/css?family=Montserrat:300,300i,400,400i,500,500i,600,600i,700,700i&quot; rel=&quot;stylesheet&quot;&gt;
      &lt;script&gt;  
   $(document).ready(function(){  
        var i=1;  
        $('#add').click(function(){  
             i++;  
              $('#dynamic_field').append('&lt;div class=&quot;form-group&quot; id=&quot;row'+i+'&quot;&gt;&lt;label&gt;Question '+i+'&lt;/label&gt;&lt;input type=&quot;text&quot; name=&quot;question[]&quot; class=&quot;form-control&quot;/&gt;&lt;input type=&quot;hidden&quot; name=&quot;noquestion[]&quot; value=&quot;'+i+'&quot;/&gt;&lt;label&gt;Selections Answer (Question '+i+')&lt;/label&gt;&lt;br&gt;a)&lt;input type=&quot;text&quot; name=&quot;answer[]&quot; class=&quot;form-control&quot;/&gt; &lt;br&gt;'+
              'b)&lt;input type=&quot;text&quot; name=&quot;answer[]&quot; class=&quot;form-control&quot;/&gt; &lt;br&gt;c)&lt;input type=&quot;text&quot; name=&quot;answer[]&quot; class=&quot;form-control&quot;/&gt; &lt;br&gt;d)&lt;input type=&quot;text&quot; name=&quot;answer[]&quot; class=&quot;form-control&quot;/&gt; &lt;br&gt;&lt;br&gt;&lt;center&gt;&lt;button type=&quot;button&quot; name=&quot;remove&quot; id=&quot;'+i+'&quot; class=&quot;btn btn-danger btn_remove&quot;&gt;X&lt;/button&gt;&lt;/center&gt;&lt;/div&gt;');  
        });  
        $(document).on('click', '.btn_remove', function(){  
             var button_id = $(this).attr(&quot;id&quot;);   
             $('#row'+button_id+'').remove();  
        });  
        
   });  
   &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;?php include_once('includes/header.php');?&gt;
      &lt;?php include_once('includes/sidebar.php');?&gt;
          
      &lt;div class=&quot;col-sm-9 col-sm-offset-3 col-lg-10 col-lg-offset-2 main&quot;&gt;
          &lt;div class=&quot;row&quot;&gt;
              &lt;ol class=&quot;breadcrumb&quot;&gt;
                  &lt;li&gt;&lt;a href=&quot;#&quot;&gt;
                      &lt;em class=&quot;fa fa-home&quot;&gt;&lt;/em&gt;
                  &lt;/a&gt;&lt;/li&gt;
                  
              &lt;/ol&gt;
          &lt;/div&gt;&lt;!--/.row--&gt;
          
          &lt;div class=&quot;row&quot;&gt;
              &lt;div class=&quot;col-lg-12&quot;&gt;
              
                  &lt;div class=&quot;panel panel-default&quot;&gt;
                      &lt;div class=&quot;panel-body&quot;&gt;
                          &lt;p style=&quot;font-size:16px; color:red&quot; align=&quot;center&quot;&gt;
                              
                          &lt;div class=&quot;col-md-12&quot;&gt;
                              
                              &lt;form role=&quot;form&quot; method=&quot;post&quot; action=&quot;&quot;&gt;
                                  
                                  &lt;div class=&quot;control-group&quot; id=&quot;dynamic_field&quot;&gt;
                                  &lt;div class=&quot;form-group&quot;&gt;
                                  &lt;label&gt;Question 1&lt;/label&gt;
                                  &lt;input type=&quot;text&quot; name=&quot;question[]&quot; class=&quot;form-control&quot;/&gt;
                                  &lt;input type=&quot;hidden&quot; name=&quot;noquestion[]&quot; value=&quot;1&quot;/&gt;
                                  &lt;br&gt;
                                  
                                  &lt;label&gt;Selections Answer (Question 1)&lt;/label&gt;&lt;br&gt;
                                  a)&lt;input type=&quot;text&quot; name=&quot;answer[]&quot; class=&quot;form-control&quot;/&gt; &lt;br&gt;
                                  b)&lt;input type=&quot;text&quot; name=&quot;answer[]&quot; class=&quot;form-control&quot;/&gt; &lt;br&gt;
                                  c)&lt;input type=&quot;text&quot; name=&quot;answer[]&quot; class=&quot;form-control&quot;/&gt; &lt;br&gt;
                                  d)&lt;input type=&quot;text&quot; name=&quot;answer[]&quot; class=&quot;form-control&quot;/&gt; &lt;br&gt;
                                  &lt;/div&gt;
                                  &lt;br&gt;
                                  &lt;center&gt;&lt;a  name=&quot;add&quot; id=&quot;add&quot; class=&quot;btn btn-success&quot;&gt;Add Question&lt;/a&gt;&lt;/center&gt;&lt;br&gt;
                                  &lt;/div&gt;
                                                              
                                  &lt;div class=&quot;form-group has-success&quot;&gt;
                                      &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary&quot; name=&quot;submit&quot; onclick=&quot;return confirm('Are you sure to proceed?');&quot;&gt;Save&lt;/button&gt;
                                  &lt;/div&gt;
                                  &lt;/form&gt;
                                  
                                  &lt;/div&gt;
                              
                              
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;&lt;!-- /.panel--&gt;
              &lt;/div&gt;&lt;!-- /.col--&gt;
              &lt;?php include_once('includes/footer.php');?&gt;
          &lt;/div&gt;&lt;!-- /.row --&gt;
      &lt;/div&gt;&lt;!--/.main--&gt;
      
  &lt;script src=&quot;js/jquery-1.11.1.min.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;js/bootstrap.min.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;js/chart.min.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;js/chart-data.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;js/easypiechart.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;js/easypiechart-data.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;js/bootstrap-datepicker.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;js/custom.js&quot;&gt;&lt;/script&gt;
      
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>Current output :</p>
  <p><a href="https://i.stack.imgur.com/prxTd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/prxTd.png" alt="enter image description here" /></a></p>
  <p>Expected Output :</p>
  <p><a href="https://i.stack.imgur.com/8Ia1H.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8Ia1H.png" alt="enter image description here" /></a></p>