title: How can I insert multiple records in mysql using php at once with one query dynamicaly?
body: <p>I have an invoice module. There I have fields for items purchased. I am using ajax/jQuery to add new rows when user want to add. Now my question is that how can I add all records in database using PHP, I know how to enter one record but don't know how to add multiple records when we don't know how much records we want to insert. Here is the code,</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Document&lt;/title&gt;
  
  &lt;script src="js/jquery-1.11.2.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
   $("#insert-more").click(function () {
       $("#JTable").each(function () {
           var tds = '&lt;tr&gt;';
           jQuery.each($('tr:last td', this), function () {
               tds += '&lt;td&gt;' + $(this).html() + '&lt;/td&gt;';
           });
           tds += '&lt;/tr&gt;';
           if ($('tbody', this).length &gt; 0) {
               $('tbody', this).append(tds);
           } else {
               $(this).append(tds);
           }
       });
  });
  
  &lt;/script&gt;
  
  
  &lt;/head&gt;
  
  &lt;body&gt;
  
  &lt;form name="items" method="post"&gt;
  &lt;table id="JTable" style="margin-left:50px;"&gt;
      &lt;thead&gt;
          &lt;th class="tblfldname"&gt;Product&lt;/th&gt;
          &lt;th class="tblfldname"&gt;Quantity&lt;/th&gt;
          &lt;th class="tblfldname"&gt;Price&lt;/th&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
                &lt;select name="pname[]" class="pname" style="padding:4px; width:150px;"&gt;
  
                      &lt;option&gt;&lt;/option&gt;
  
                &lt;/select&gt;
              &lt;/td&gt;
              &lt;td&gt;
                &lt;input type="text" name="qty[]" style="width:150px; padding:4px;" /&gt;
              &lt;/td&gt;
              &lt;td&gt;
                &lt;input type="text" name="price[]" class="price" style="width:150px; padding:4px;" /&gt;
  
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
                   &lt;input type="submit" name="submit" /&gt;
  
  &lt;/table&gt;
  &lt;/form&gt;
              &lt;a href="#" id="insert-more"&gt; Add New Row &lt;/a&gt;
  
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>P.S. All new generated rows's fields have same name.</p>