title: Dynamically Add / Remove multiple input fields in PHP with Jquery Ajax
body: <p>This is the HTML of my form</p>
  
  <pre><code>&lt;div class="crcform"&gt;
  
            &lt;h1&gt;Internship Details&lt;/h1&gt;
  
            &lt;form name="internship_details" id="intership_details"&gt;
            &lt;table class="table table-bordered" id="dynamic_field"&gt;
                  &lt;tr&gt;
                  &lt;td&gt;
            &lt;!--div class="top-row"--&gt;
              &lt;div class="field-wrap"&gt;
                &lt;label&gt;
                  Company&lt;span class="req"&gt;*&lt;/span&gt;
                &lt;/label&gt;
                &lt;input type="text" required autocomplete="off" name="company[]"/&gt;
              &lt;/div&gt;
  
            &lt;div class="field-wrap"&gt;
              &lt;label&gt;
                Project&lt;span class="req"&gt;*&lt;/span&gt;
              &lt;/label&gt;
              &lt;input type="text"required autocomplete="off" name="project[]"/&gt;
            &lt;/div&gt;
  
            &lt;div class="field-wrap"&gt;
              &lt;label&gt;
                Duration&lt;span class="req"&gt;*&lt;/span&gt;
              &lt;/label&gt;
              &lt;input type="text"required autocomplete="off" name="duration[]"/&gt;
            &lt;/div&gt;
  
            &lt;div class="field-wrap"&gt;
              &lt;label&gt;
                Key Learning&lt;span class="req"&gt;*&lt;/span&gt;
              &lt;/label&gt;
              &lt;input type="text"required autocomplete="off" name="key_learning[]"/&gt;
            &lt;/div&gt;&lt;/td&gt;
            &lt;td&gt;&lt;button type="button" name="add" id="add" class="btn btn-success"&gt;Add More&lt;/button&gt;&lt;/td&gt;
           &lt;/tr&gt;
           &lt;/table&gt;
           &lt;input type="button" name="submit" id="submit"  class="btn btn-info" value="Submit" /&gt;
            &lt;!--div class="top-row"&gt;
            &lt;div class="field-wrap"&gt;
            &lt;button class="button button-block" name="submit" id="submit"/&gt;NEXT&lt;/button&gt; 
            &lt;/div--&gt;
  
            &lt;/form&gt;
            &lt;/div&gt;
  </code></pre>
  
  <p>this is javascript of dynamically add/remove form</p>
  
  <pre><code>&lt;script&gt;
  $(document).ready(function(){
      var i = 1;
      $('#add').click(function(){
          i++;
          $('#dynamic_field').append('&lt;tr id="row'+i+'"&gt;&lt;td&gt;&lt;div class="field-wrap"&gt;&lt;label&gt;Company&lt;span class="req"&gt;*&lt;/span&gt;&lt;/label&gt;&lt;input type="text" required autocomplete="off" name="company[]"/&gt;&lt;/div&gt;&lt;div class="field-wrap"&gt;&lt;label&gt;Project&lt;span class="req"&gt;*&lt;/span&gt;&lt;/label&gt;&lt;input type="text"required autocomplete="off" name="project[]"/&gt;&lt;/div&gt;&lt;div class="field-wrap"&gt;&lt;label&gt;Duration&lt;span class="req"&gt;*&lt;/span&gt;&lt;/label&gt;&lt;input type="text"required autocomplete="off" name="duration[]"/&gt;&lt;/div&gt;&lt;div class="field-wrap"&gt;&lt;label&gt;Key Learning&lt;span class="req"&gt;*&lt;/span&gt;&lt;/label&gt;&lt;input type="text"required autocomplete="off" name="key_learning[]"/&gt;&lt;/div&gt;&lt;/td&gt;&lt;/td&gt;&lt;td&gt;&lt;button name="remove" id="'+i+'" class="btn btn-danger btn_remove"&gt;X&lt;/button&gt;&lt;/td&gt;&lt;/tr&gt;');
      });
      $(document).on('click','.btn_remove', function(){
          var button_id = $(this).attr("id");
          $("#row"+button_id+"").remove();
      });
  
      $('#sumbit').clic(function(){
          $.ajax({
              url:"internship_details.php",
              method:"POST",
              data:$('#internship_details').serialize(),
              success:function(data)
              {
                  alert(data);
                  $('#internship_details')[0].reset();
              }
          });
      });
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>this is the php code to store data in database</p>
  
  <pre><code>&lt;?php
  
  include 'connection.php';
  
  $number = count($_POST["company"]);
  if ($number &gt; 0){
      for($i = 0; $i &lt; $number; $i++){
          if(trim($_POST["company"][$i]) != ''){
          $sql = "INSERT INTO internship VALEUS('".mysqli_real_escape_string($connect, $_POST["company"][$i]."')";
          mysqli_query($connect, $sql);
          }
      }
      echo 'Data Inserted';
  }
  else{
      echo "Enter Name";
  }
  ?&gt;
  </code></pre>
  
  <p>I'm unable to store the value in database. Can anyone tell me where im going wrong?
  Can you also tell me what its insert query will be because i'm adding more than one column in a row. So help me with this</p>