title: How to insert multiple row data from a table into another table in MySQL using checkboxes
body: <p>I trying to insert my data from table_request into table_list by clicking the approve/reject button under the table.</p>
  <p>Users will click the checkboxes to select all or select a specific row. After approve, the data in the table_request insert into table_list and deleted from table_request.</p>
  <p>The current problem is about the foreach and inserts statement is wrong.
  After I click approve, it can only insert table_request id into table_list.</p>
  <p>This is my table_request.php</p>
  <pre><code>&lt;form name=&quot;bulk_action_form&quot; action=&quot;action.php&quot; method=&quot;post&quot; onSubmit=&quot;return approve_confirm();&quot;/&gt;
  &lt;table class=&quot;bordered&quot;&gt;
  &lt;tr&gt;
    &lt;th&gt;&lt;input type=&quot;checkbox&quot; name=&quot;select_all&quot; id=&quot;select_all&quot; value=&quot;&quot;/&gt;&lt;/th&gt;        
    &lt;th&gt;Name&lt;/th&gt;
    &lt;th&gt;Remark&lt;/th&gt;
  &lt;/tr&gt;
  
  &lt;?php
    $query = &quot;select * from `table_request`;&quot;;
    if(count(fetchAll($query))&gt;0){
    foreach(fetchAll($query) as $row){
  ?&gt;
  
      &lt;tr&gt;
      &lt;td&gt;&lt;input type=&quot;checkbox&quot; name=&quot;checked_id[]&quot; class=&quot;checkbox&quot; value=&quot;&lt;?php echo $row['id']; ?&gt;&quot;/&gt;&lt;/td&gt;
      &lt;td&gt;&lt;?php echo $row['Name'] ?&gt;&lt;/td&gt;
      &lt;td&gt;&lt;?php echo $row['Remark'] ?&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;?php } }else{ ?&gt;
          &lt;tr&gt;&lt;td colspan=&quot;5&quot;&gt;No records found.&lt;/td&gt;&lt;/tr&gt; 
      &lt;?php } ?&gt;
  
  &lt;/table&gt;
  &lt;input type=&quot;submit&quot; name=&quot;approve_btn&quot; value=&quot;Approve&quot;/&gt;
  &lt;/form&gt;
  </code></pre>
  <p>This is my action.php</p>
  <pre><code>&lt;?php
  session_start();
  include_once('connection.php');
  if(isset($_POST['approve_btn']))
  {
      $idArr = $_POST['checked_id'];
      $Name  = $_POST['Name'];
      $Remark = $_POST['Remark'];
      foreach($idArr as $key =&gt; $value)
      {
          $save = &quot;INSERT INTO table_list(id,Name,Remark) VALUES ('&quot;.$value.&quot;','&quot;.$Name[$key].&quot;','&quot;.$Remark[$key].&quot;')&quot;;
                  $query = mysqli_query($conn,$save);
      }
      $query .= &quot;DELETE FROM `table_request` WHERE `table_request`.`id` = '$id';&quot;;
      header(&quot;Location:table_request.php&quot;);
  }
  ?&gt;
  </code></pre>