Update Checkbox Value Using PHP & MySQL

This code will send exactly two query’s to update a INT (0 or 1) checkbox field in a MySQL database.

The IN operational statement let’s you match on a list of values in a clause. The implode statement will turn the array (shown below) into a string.




The checkboxes are populated through a while loop (not shown). Each checkbox has the same name, but a unique value. The $id variable is the unique field that is populated from the database. Include brackets [] in order to turn the field into an array.
if($database['checkbox'] == 1) { $set_checked = "CHECKED";}
else{$set_checked = ""; }
print "";