Skip to content
Advertisement

Update sql database by clicking checkbox without submit button using ajax

I am searching for a way to update my sql database without refreshing the page by selecting the checkbox. I am trying to achieve the id to be passed to the dolead.php when the user selects the checkbox and than check whether the id is higher than 0 it must pass the value 1 otherwise the value 0. Afther that check i need the database to be updated with the where clause the posted id. Below my code, what am i doing wrong? i get no errors in my logs and i have the error logging stated as followed: mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

PHP the user is seeing to select the switch box to trigger a select and the jquery to trigger the post.

JavaScript

The dolead.php to retrieve the post value and update the database;

JavaScript

PS: the connection file is included but not shown here..

Advertisement

Answer

You could add a class to the input and set the value dynamically:-

View:-

JavaScript

jQuery/AJAX Call:-

JavaScript

PHP:-

JavaScript

Note:- for more info regarding click()

https://api.jquery.com/click

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