title: How to insert multiple data into a table
body: <p>I have a table and every row items have an addtocart button each and when i click the addtocart button, a modal shows and it has ok button for the qty that i want to order, when i click ok button another modal will show and it has the table form like the first table and it shows the items that i ordered, and when I click the ok button, I want that rows to be inserted on the database.</p>
  
  <pre><code>$( $table ).delegate(".Addtocart", "click", function() {
                  var itemNo = $(this).closest('tr').find('td.itemNo').html();
                  var selected_item = $(this).closest('tr').find('td.itemdescr').html();
                  var remaining_qty = $(this).closest('tr').find('td.currqty').html();
                  var unitPrice = $(this).closest('tr').find('td.unit_price').html();
                  var amount = $(this).closest('tr').find('td.Amount').html();
                  $("#action").val('add');
                  $('#itemNo').val(itemNo);
                  $('#selected_item').val($.trim(selected_item));
                  $('#remaining_qty').val(remaining_qty);
                  $('#unitPrice').val(unitPrice);
                  $('#amount').val(amount);
                  $('#myModal').modal('show');
              }); 
  </code></pre>
  
  <p>heres the 2nd ok button for the 2nd modal</p>
  
  <pre><code>$('#OKBtn2').click(function(){
              $('#myModal2').modal('hide');
              var itemid = $('#main-form2 .active').attr('id'),
                  qty = $('#main-form2 #'+itemid+' td:eq(2)').text(),
                  amount = $('#main-form2 #'+itemid+' td:eq(4)').text();
                  bootbox.confirm("Are you sure?","No","Yes",function(r){
                      if(r) {
                          var itemno = $('#itemNo').val();
  //                        var currqty = $('#orderqty').val();
                          var unit_price = $('#unitPrice').val();
  //                        var Amount = $('#amount').val();
                          $.ajax({  
                              url : url,
                              type : "POST",
                              async : false,
                              data : {
                                      Modify: 1,
                                      Delete:1,
                                      Add: 1,
                                      itemNo: itemno,
                                      orderqty: qty,
                                      unit_price: unit_price,
                                      amount: amount,
                                      todo:"Add"
                                         },
                          success:function(result){
                          bootbox.alert('Ordered',function(){
                          });
                          updateTable();
                          }
                      });
  
                      } else {
  
                      }
                  });
              });
  </code></pre>
  
  <p>how can I convert this into an array? The data inserts to the table but it inserts the row item that is selected or highlighted only, it doesn't inserts the other row items. the row has class that when you click it highlights the row.</p>
  
  <pre><code>case "Add":
          if(isset($_POST['Add'])){
                      $Addquery = "INSERT INTO tb_empgrocery (empgrocID, coopmemID , date_ordered, item_no, qty_ordered, unit_price, amount, date_delivered, qty_delivered, order_status, released_by) VALUES ('".$_POST['empgrocID']."', '".$login['is_coopmemID_kiosk']."', (NOW()), '".$_POST['itemNo']."', '".$_POST['orderqty']."', '".$_POST['unit_price']."', '".$_POST['amount']."', '".$_POST['date_delivered']."', '".$_POST['qty_delivered']."','".$_POST['order_status']."','".$_POST['released_by']."')";
                      mysql_query($Addquery, $con);
                      }
          break;
  </code></pre>
  
  <p>is this correct?</p>
  
  <pre><code>case "Add":
              $_POST = array_map('addlashes', $_POST);
              $values = array();
                  foreach ($_POST as $key =&gt; $value) {
                      $values[] = "('{$_POST['empgrocID']}', '{$login['is_coopmemID_kiosk']}', '{$_POST['(NOW())']}', '{$_POST['itemNo']}', '{$_POST['orderqty']}', '{$_POST['unit_price']}', '{$_POST['amount']}', '{$_POST['date_delivered']}', '{$_POST['qty_delivered']}', '{$_POST['order_status']}', '{$_POST['released_by']}')";
                  }
                  if(sizeof($values)) {
                      $query = "INSERT INTO tb_empgrocery (empgrocID, coopmemID , date_ordered, item_no, qty_ordered, unit_price, amount, date_delivered, qty_delivered, order_status, released_by) VALUES ".implode(',', $values);
                      $result = mysql_query($query, $con);
                  }
          break;
  </code></pre>
  
  <p>Thanks in advance</p>