PHP Inline Editing Data using jQuery AJAX

In this tutorial, we are going to create PHP Inline Editing Data using jQuery AJAX. The previous tutorial, we create Inline Adding Data tutorial we have done in the same process using AJAX jQuery. This tutorial, we are going to edit the data in the database table in an inline form in the web page. The user will allow editing the data on clicking the content in the web page in the inline form. You can also check the live demo of this simple tutorial, so you can get an idea and you can try this out, let's start coding. Create Simple Markup This simple source code shows the simple content that we have where the user can edit data in the inline form.
  1. <table class="tbl-qa">
  2.   <thead>
  3.         <tr>
  4.           <th class="table-header">Product Name</th>
  5.           <th class="table-header">Product Quantity</th>
  6.           <th class="table-header">Action</th>
  7.         </tr>
  8.   </thead>
  9.   <tbody id="table-body">
  10.         <?php
  11.         if(!empty($row_product)) {
  12.         foreach($row_product as $k=>$v) {
  13.           ?>
  14.           <tr class="table-row" id="table-row-<?php echo $row_product[$k]["id"]; ?>">
  15.                 <td contenteditable="true" onBlur="saveToDatabase(this,'product_name','<?php echo $row_product[$k]["id"]; ?>')" onClick="editRow(this);">
  16.                         <?php echo $row_product[$k]["product_name"]; ?>
  17.                 </td>
  18.                 <td contenteditable="true" onBlur="saveToDatabase(this,'product_qty','<?php echo $row_product[$k]["id"]; ?>')" onClick="editRow(this);">
  19.                         <?php echo $row_product[$k]["product_qty"]; ?>
  20.                 </td>
  21.                 <td>
  22.                         <a class="ajax-action-links" onclick="deleteRecord(<?php echo $row_product[$k]["id"]; ?>);">
  23.                                 Delete
  24.                         </a>
  25.                 </td>
  26.           </tr>
  27.           <?php
  28.         }
  29.         }
  30.         ?>
  31.   </tbody>
  32. <div class="add-data-style" id="add-more" onClick="createNew();">Add More</div>
Edit Query Copy and paste this simple query for edit function and save it as "edit.php".
  1. <?php
  2. require_once("database.php");
  3. $query = new EditDataInlineForm();
  4. $result_row = mysql_query("UPDATE tbl_products_inline set " . $_POST["column"] . " = '".$_POST["editval"]."' WHERE  id=".$_POST["id"]);
  5. ?>

Output

Result Read Also: Inline Adding Data For the full source code, kindly click the "Download Code" button below. If you try all the examples, you will learn a lot about PHP, in a very short time! Share us your thoughts and comments below. Thank you so much for dropping by and reading this tutorial post. For more updates, don’t hesitate and feel free to visit this website more often and please share this with your friends or email me at [email protected]. Practice Coding. Thank you very much.

Add new comment