Skip to content
Advertisement

Database update through checkbox change

For my thesis, I am working on a program for checking cars. Currently, I am working on the user management now I have encountered the problem that the database needs to be updated when a checkbox is changed status.

Image checkboxes:
Image checkboxes

Now I have already started looking a bit on how to execute a PHP function when this happens, and I ended up with a JavaScript AJAX function

JavaScript

Now I have the problem that I do not know what to include with data because I have several checkboxes that are being shot by PHP. I don’t know exactly how to update my database. Do I have to run all over the table to detect changes?

Code from my table:

JavaScript

Advertisement

Answer

Listed for changes on the checkboxes. A simple way to do that is assign a class like ‘mycheckbox’ to each one so you can easily find them all. Once the page is loaded, add the change event trigger to the checkboxes.

JavaScript

Your php script would be something like this:

JavaScript

This is a very basic example, and of course you’d want to sanitize or validate the data if you plan to insert any of it into the DB.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement