Question: How do i make it that when i click on a checkbox it saves it automatically into the database when the save button is pressed.

How do i make it that when i click on a checkbox it saves it automatically into the database when the save button is pressed. It should save in the way as displayed in the screenshot of the database shown. Currently, all i can do is manually type it in the database and it reflects on the checkboxes on the order page.
save.php
query($sql);
if ($result->num_rows >0){
$row = $result->fetch_assoc();
} else {
echo "No record found.";
exit();
}
if (isset($_POST['saveButton'])){
if (isset($_POST['sizes'])){
$sizes = $_POST['sizes'];
$sizeString = implode(',', $sizes);
$query = "UPDATE `testdatabase3` SET `size`='$sizeString' WHERE `id`= $id";
$run = mysqli_query($conn, $query);
if ($run){
header("Location: orders.php");
exit();
} else {
echo "Error updating record: ". $conn->error;
}
} else {
echo "No size selected.";
}
}
} else {
echo "Invalid request.";
exit();
}
?>
ordertable:
// Fetch and display the results
while($row = $result->fetch_assoc()){
$sizes = explode(',', $row['size']);
$sizeChecked = function($size) use ($sizes){
return in_array($size, $sizes)? 'checked' : '';
};
echo "
 How do i make it that when i click on a

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!