title: Delete a database row using JQuery
body: <p>I am using a PHP function to format any 2D PHP array to HTML table, In that table I need to add a delete button in each row, So when the user clicks the delete button jQuery should take particular fields ( 3 fields ) and submit in a php file and it should give the response without reloading the page, I have several dynamic tables in same PHP files, So i have used $table_name as the form ID to differentiate the FORMS, and In the del.php ( Where my form get submitted ) I decide which table should I look up to delete the row using the PRIMARY KEY. My Problem is Do I have to create Forms Within each table to do this task? or can I simply put some  fields and submit the form using jQuery? </p>
  
  <p>Any help would be much appreciable .</p>
  
  <pre><code>function formatArrayToTable($foo, $deletable = 0, $restaurant_id ='', $table_name = '') {
    //open table
    echo '&lt;table class="imagetable"&gt;';
  
    // our control variable
    $first = true;
  
    foreach($foo as $key1 =&gt; $val1) {
      //if first time through, we need a header row
      if($first){
        echo '&lt;tr&gt;';
        foreach($val1 as $key2 =&gt; $value2) {
          echo '&lt;th&gt;'.$key2.'&lt;/th&gt;';
        }
  
        if($deletable) {
          echo "&lt;th&gt;'Delete'&lt;/th&gt;";
        }
  
        echo '&lt;/tr&gt;';
  
        //set control to false
        $first = false;
      }
  
      echo '&lt;tr&gt;';
  
      foreach($val1 as $key2 =&gt; $value2) {
        echo '&lt;td&gt;'.$value2.'&lt;/td&gt;';
      }
  
      if($deletable) {
        $primary = $val1["id"];
  
        echo "&lt;input type='hidden' name='table_name' value='{$table_name}' /&gt;";
        echo "&lt;input type='hidden' name='restaurant_id' value='{$restaurant_id}' /&gt;";
        echo "&lt;td&gt;&lt;input class='delete_class' type=\"button\" name=\"delete_id\" value={$primary} onclick='SubmitForm($table_name)'/&gt;&lt;/td&gt;" ;
      }
      echo '&lt;/tr&gt;';
    }
    echo '&lt;/table&gt;';
  }
  </code></pre>
  
  <p>My Javascript Function </p>
  
  <pre><code>function SubmitForm(formId){
    var message = "";
    $("#"+formId+" input").each(function() {
      message += $(this).attr("name");
    });
  
    $.ajax({
      type: "POST",
      url: "del.php",
      data: message,
      success: 
        function() {
          $('#message').html("&lt;h2&gt;Contact Form Submitted!&lt;/h2&gt;")
            .append("&lt;p&gt;Entry is Deleted &lt;/p&gt;")
            .hide()
        }
    });
  }
  </code></pre>
  
  <p>-Regards</p>