Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End How to update database onclick? Reply To: How to update database onclick?

#242571
rkieru
Participant

This strikes me as more of a Javascript problem than one directly-related to PHP. If my understanding is correct, you are providing a button that will allow an authorized user to change the access level of a user when clicked.

So there are two ways to achieve this.

Apply and Redirect

In a scenario like this the button would either be a link or a form that takes the user off the current page, applies the update, and then returns the user to the original page.

So for example: <a href="level.update.php?user=25&level=2">...</a>

The user would then be directed to that page (assume it has the code you presented above) and then redirected upon completion back to the list of users via header("Location: path/to/list");

Apply Asynchronously

In a scenario like this, the button would function much the same, except you would be submitting the call via AJAX and notifying the user of the results. In this situation the user would never leave the current page.

For this to work you would have a button or link of some sort keyed to a Javascript AJAX call. How you handle parsing the various information is up to you, whatever Javascript libraries you are using (if any), etc. With jQuery this would be via $.ajax().