Updating database with ajax

I am trying to write a script that will update my database(s) without the user having to click any buttons.

I also want the update to occur whenever a field is modified in the form.

For example, after performing the database insert, it returns the HTML to display the newly added record in the list.

On editing a record this code will respond the edited text content to the AJAX.

Let us learn how to add, edit and delete records in My SQL database using PHP via AJAX.

If you are looking for a non-AJAX plain PHP CRUD, go through my previous tutorial.

In each case, I send the required CRUD action to be performed with other AJAX parameters.

In PHP the action parameter is received and used to dispatch to the suitable case to perform the database action.

In this example, I have implemented the database CRUD for the comment system with AJAX.

In the AJAX success block, I received the response text or HTML to update the user about the database action.

This PHP code deals with the database CRUD actions using switch cases.

But the script I'm using assigns the updated value to the same variable every time (in this case it's 'q').

the javascript looks like this (I found this on the web all over the place) I see why the variable 'q' ends up being what is passed to the db update script.

Search for updating database with ajax:

updating database with ajax-63updating database with ajax-70

Is there a way to write the script so that it will dynamically figure out the field name (I will use the database field name as the form field name, to keep it simple) and assign THAT field name to the $_GET's name?

Leave a Reply

Your email address will not be published. Required fields are marked *

One thought on “updating database with ajax”