title: Update Database After Button Click
body: <p>I have a dynamic table that can be edited inline or can have rows dynamically added. I want to be able to hit a save button that runs an UPDATE query to update the database. But I can't figure out how. I am really stuck on this and would appreciate any help.</p>
  
  <p>Here is a codepen: <a href="http://codepen.io/anon/pen/yawyQQ" rel="nofollow">http://codepen.io/anon/pen/yawyQQ</a></p>
  
  <p>You can find most code in the codepen...I will provide some of my HTML/PHP code and Ajaxsubmit code.</p>
  
  <p>HTML/PHP code:</p>
  
  <pre><code>&lt;html&gt;
  
      &lt;head&gt;
          &lt;title&gt;Stage Rebate Master HTML Table&lt;/title&gt;
          &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"&gt;&lt;/script&gt;
           &lt;script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"&gt;&lt;/script&gt;
           &lt;link rel="stylesheet" type="text/css" href="html_master.css"&gt;
           &lt;link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"&gt;
          &lt;script type="text/javascript" src="html_master.js"&gt;&lt;/script&gt;
      &lt;/head&gt;
  
      &lt;label id="table_name"&gt;Stage_Rebate_Master&lt;/label&gt;&lt;br&gt;
  
  &lt;body&gt;    
  
  &lt;div id="dialog-form" title="Add Vendor"&gt;
    &lt;p class="validateTips"&gt;All form fields are required.&lt;/p&gt;
  
    &lt;form&gt;
      &lt;fieldset&gt;
        &lt;label for="mr_name"&gt;Vendor&lt;/label&gt;
        &lt;input type="text" name="mr_name" id="mr_name" class="text ui-widget-content ui-corner-all"&gt;
        &lt;label for="buyer_id"&gt;Buyer ID&lt;/label&gt;
        &lt;input type="text" name="buyer_id" id="buyer_id" class="text ui-widget-content ui-corner-all"&gt;
        &lt;label for="poc_n"&gt;POC Name&lt;/label&gt;
        &lt;input type="text" name="poc_n" id="poc_n" class="text ui-widget-content ui-corner-all"&gt;
        &lt;label for="poc_p"&gt;POC Email&lt;/label&gt;
        &lt;input type="text" name="poc_e" id="poc_e" class="text ui-widget-content ui-corner-all"&gt;
        &lt;label for="poc_p"&gt;POC Phone&lt;/label&gt;
        &lt;input type="text" name="poc_p" id="poc_p" class="text ui-widget-content ui-corner-all"&gt;
  
        &lt;!-- Allow form submission with keyboard without duplicating the dialog button --&gt;
        &lt;input type="submit" id="submit" tabindex="-1" style="position:absolute; top:-1000px"&gt;
      &lt;/fieldset&gt;
    &lt;/form&gt;
  &lt;/div&gt;
  
  
  
  &lt;div id="users-contain" class="ui-widget"&gt;
  &lt;table id="html_master" class="ui-widget ui-widget-content"&gt;
  &lt;thead&gt;
      &lt;tr class="ui-widget-header"&gt;
      &lt;td&gt;ID&lt;/td&gt;
      &lt;td&gt;Vendor&lt;/td&gt;
      &lt;td&gt;Buyer ID&lt;/td&gt;
      &lt;td&gt;POC Name&lt;/td&gt;
      &lt;td&gt;POC Email&lt;/td&gt;
      &lt;td&gt;POC Phone&lt;/td&gt;
      &lt;td&gt;Edit/Delete&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
  
  &lt;?php
      foreach ($dbh-&gt;query($sql) as $rows){
      ?&gt;
      &lt;tr&gt;
          &lt;td class="mr_id" contenteditable="false"&gt;&lt;?php echo intval ($rows['MR_ID'])?&gt;&lt;/td&gt;
          &lt;td class="mr_name" contenteditable="false"&gt;&lt;?php echo $rows['MR_Name']?&gt;&lt;/td&gt;
          &lt;td class="buyer_id" contenteditable="false"&gt;&lt;?php echo $rows['Buyer_ID']?&gt;&lt;/td&gt;
          &lt;td class="poc_n" contenteditable="false"&gt;&lt;?php echo $rows['MR_POC_N']?&gt;&lt;/td&gt;     
          &lt;td class="poc_e" contenteditable="false"&gt;&lt;?php echo $rows['MR_POC_E']?&gt;&lt;/td&gt;
          &lt;td class="poc_p" contenteditable="false"&gt;&lt;?php echo $rows['MR_POC_P']?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input type="button" class="edit" name="edit" value="Edit"&gt;
          &lt;input type="button" class="deactivate" name="deactivate" value="Deactivate"&gt;&lt;/td&gt;
      &lt;/tr&gt;
   &lt;?php
    }
   ?&gt;
  &lt;/tbody&gt;
  
      &lt;input type="button" class="create-user" value="Add Row"&gt;
      &lt;input type="submit" value="Save Table" class="save"&gt;
  
  &lt;/table&gt;
  &lt;/div&gt;
  
      &lt;input type="button" class="create-user" value="Add Row"&gt;
      &lt;input type="submit" value="Save Table" class="save"&gt;
  
  &lt;/body&gt;
  
  
  &lt;/html&gt;
  </code></pre>
  
  <p>Ajaxsubmit code:</p>
  
  <pre><code>&lt;?php
  
  $host="xxxx"; 
  $dbName="xxxxxxx"; 
  $dbUser="xxxxx"; 
  $dbPass="xxxxxxxxxxxx";
  
  $dbh = new PDO( "sqlsrv:server=".$host."; Database=".$dbName, $dbUser, $dbPass);
  $dbh-&gt;setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
  
  
  $data = $_POST['data'];
  foreach($data as $row){
      $sql = "UPDATE Stage_Rebate_Master SET MR_Name='$row[mr_name]',
      Buyer_ID='$row[buyer_id]',
      MR_POC_N='$row[poc_n]',
      MR_POC_E='$row[poc_e]',
      MR_POC_N='$row[poc_p]'
      WHERE MR_ID='$row[mr_id]'";
  
      $dbh-&gt;query($sql);
  }
  
  ?&gt;
  </code></pre>