title: Trying to insert data into another table on button click
body: <p>I have a form that takes data from the db and displays it onto a table using a foreach loop. After reviewing the data, I want to insert that data into another table that is already in the DB via a button click. I have tried multiple ways, but can't seem to get it to work. Any help would be great. Thanks!</p>
  
  <p>my index.php page </p>
  
  <pre><code>&lt;div class='container-fluid'&gt;
    &lt;div class='row'&gt;
      &lt;div class='col-12'&gt;
        &lt;div class='table table-responsive'&gt;
          &lt;table class='table table-striped table-bordered datatable active' id='grantTable'&gt;
            &lt;thead&gt;
                &lt;tr&gt;
                  &lt;th&gt;FP ID&lt;/th&gt;
                  &lt;th&gt;Short Title&lt;/th&gt;
                  &lt;th&gt;PI&lt;/th&gt;
                  &lt;th&gt;Department&lt;/th&gt;
                  &lt;th&gt;Division&lt;/th&gt;
                  &lt;th&gt;Sponsor Name&lt;/th&gt;
                  &lt;th&gt;Project Start&lt;/th&gt;
                  &lt;th&gt;Project End&lt;/th&gt;
                  &lt;th&gt;Funding Type&lt;/th&gt;
                  &lt;th&gt;Yes/No&lt;/th&gt;
                  &lt;th&gt;Proper Type If No&lt;/th&gt;
                  &lt;th&gt;Comment&lt;/th&gt;
                &lt;/tr&gt;
            &lt;/thead&gt;
            &lt;tbody&gt;
              &lt;?php
              //Foreach loop iterates through each column of $getallrows function
              foreach($allRows as $rowID =&gt; $rowInfo){ ?&gt;
                &lt;tr&gt;
                  &lt;td&gt;&lt;?php echo $rowInfo['fpID'];?&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;?php echo $rowInfo['shortTitle'];?&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;?php echo $rowInfo['PI'];?&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;?php echo $rowInfo['Department'];?&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;?php echo $rowInfo['Division'];?&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;?php echo $rowInfo['sponsorName'];?&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;?php echo $rowInfo['Date_Project_Start']-&gt;format('Y-m-d');?&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;?php echo $rowInfo['Date_Project_End']-&gt;format('Y-m-d');?&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;?php echo $rowInfo['fundingType'];?&gt;&lt;/td&gt;
                  &lt;!-- //Create dynamic id --&gt;
                  &lt;?php $rdDrop = "ddgrantType_".$rowInfo['fpID'];?&gt;
                  &lt;form action="process.php" method="POST"&gt;
                  &lt;td&gt;Yes&lt;input type="radio" name="rdGrant[&lt;?php echo $rowInfo['fpID'];?&gt;]" value="Yes"  id="rdYes"             onclick="disable('&lt;?php echo $rdDrop;?&gt;')" checked/&gt;&lt;br /&gt;
                      No&lt;input type="radio" name="rdGrant[&lt;?php echo $rowInfo['fpID'];?&gt;]" value="No" id="rdNo" onclick="enable('&lt;?php echo $rdDrop;?&gt;')"/&gt;&lt;/td&gt;
                    &lt;input type="hidden" name="id" value="&lt;?php echo $fpID; ?&gt;"/&gt;
                    &lt;td&gt;
                      &lt;div class="dropdown"&gt;
                        &lt;button class="btn btn-secondary btn-sm dropdown-toggle" type="button" name="ddgrantGroup" id="&lt;?php echo $rdDrop;?&gt;" data-toggle="dropdown" disabled&gt;Select Proper Funding Type
                          &lt;span class="caret"&gt;&lt;/span&gt;
                        &lt;/button&gt;
                        &lt;ul class="dropdown-menu" aria-labelledby="ddgrantType"&gt;
                          &lt;li&gt;&lt;a data-value="Corporate Sponsor"&gt;Corporate Sponsor&lt;/a&gt;&lt;/li&gt;
                          &lt;li&gt;&lt;a data-value="Federal"&gt;Federal&lt;/a&gt;&lt;/li&gt;
                          &lt;li&gt;&lt;a data-value="Foundation Selected"&gt;Foundation Selected&lt;/a&gt;&lt;/li&gt;
                          &lt;li&gt;&lt;a data-value="Internally Funded"&gt;Internally Funded&lt;/a&gt;&lt;/li&gt;
                          &lt;li&gt;&lt;a data-value="State/Local"&gt;State/Local&lt;/a&gt;&lt;/li&gt;
                        &lt;/ul&gt;
                      &lt;/div&gt;
                    &lt;/td&gt;
                    &lt;td&gt;
                      &lt;div class="comment"&gt;
                        &lt;textarea class="form-control" aria-label="With textarea" id="grantComment" placeholder="Comments"&gt;&lt;/textarea&gt;
                      &lt;/div&gt;
                    &lt;/td&gt;
                &lt;/tr&gt;
              &lt;?php } ?&gt;
            &lt;/tbody&gt;
          &lt;/table&gt;
            &lt;div class="flex-container" id="saveBtn"&gt;
              &lt;div class="dSave"&gt;&lt;button type="submit" class="btn btn-success" name="submit" id="Save"&gt;Save&lt;/button&gt;&lt;/div&gt;
              &lt;div&gt;&lt;button type="submit" class="btn btn-success" name="Complete" id="Complete"&gt;Complete and Save&lt;/button&gt;&lt;/div&gt;
            &lt;/div&gt;
          &lt;/form&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>My process.php page</p>
  
  <pre><code>if(isset($_POST['submit'])) {
    $count = count($_POST['fpID']);
  
    for($i=0; $i &lt; count; $i++) {
      $mssql = "INSERT into some_table (FP_id, Short_Title, PI, Department, Division, Sponsor, Date_Project_Start,     Date_Project_End, Funding_Type, Yes_No, Proper_Type_If_No, Comment, Complete_Flag)
                VALUES ('"
                  $mssql .= $_POST['Funding Proposal ID'][$i] . "','";
                  $mssql .= $_POST['Short Title'][$i] . "','";
                  $mssql .= $_POST['PI'][$i] . "','";
                  $mssql .= $_POST['Department'][$i] . "','";
                  $mssql .= $_POST['Division'][$i] . "','";
                  $mssql .= $_POST['Sponsor Name'][$i] . "','";
                  $mssql .= $_POST['Date_Project_Start'][$i] . "','";
                  $mssql .= $_POST['Date_Project_End'][$i] . "','";
                  $mssql .= $_POST['Funding Type'][$i] . "','";
                  $mssql .= $_POST['Yes_No'][$i] . "','";
                  $mssql .= $_POST['Proper_Type_If_No'][$i] . "','";
                  $mssql .= $_POST['Comment][$i] . "','";
                  $mssql .= 'No' "')";
                  }
  
              header("Location: index.php");
  
        }
  
  ?&gt;
  
  </code></pre>