inline insert using jquery ajax in php

39

In this tutorial, we are going to see how to do inline insert the HTML5 table data to a database table using jQuery and AJAX. HTML5 allows editing table cells by setting contentEditable attribute as true. After adding data to the table cells, we can pass the cell data to PHP via jQuery AJAX. In the PHP page, we create insert query using cell data to store to database.

In this example, we have an HTML5 table to add product information. We enter the product data in the editable cell and confirm to store to a database on clicking a button. We use custom data attribute to store the product field name. With the reference of the field name, we get its value entered. This will be useful to form the post data to be sent to PHP via AJAX.

HTML5 Table to Insert Inline Data

The following code shows an editable HTML5 table and a Save button. In the table, the editable cells are referred with the product field name by using data attribute. After entering data by inline editing, we have to confirm to save the data to the database by using the Save button.

Store Table Data to Database via jQuery AJAX

The following jQuery script reads editable cell content with the reference of the custom attribute and form data to be posted via AJAX. PHP will use the post data and fire insert query to add this data to the database. On successful product insert, PHP page will return the newly added row as a response to the AJAX call which will be shown to the user.

The PHP file to insert data into the database is,

 

Leave A Reply

Your email address will not be published.