0
votes

I have a MYSQL table named 'orders' that I want to update from a single column of checkboxes in an html form. The code within the form is <input type='checkbox' name='completed[]' value='';>

I've looked around for a long time to see how I could submit this form and update my database with this single line of code. In other words, the column of checkboxes consists only of this code block, but there is a checkbox at the end of each row. I know that only the checked boxes will be returned in the $_POST['completed'] array.

How does one go about updating a mysql table with only one such code block? The update code is this:

update = "UPDATE orders SET completed='$completed' WHERE completed=0;"; 

Then

$res = mysqli_query($db, $sql) or die(mysql_error()); //update or error
1
Correction: the code got cut from above: ..."<td><input type='checkbox' name='completed[]' value='';" ."></td></tr>" - seaellen
Can you properly format your code please? - GROVER.
I'm only adding the relevant parts of code. - seaellen
you still need to properly format it... - GROVER.
Would you like all of it? Being new to Stackoverflow, I will say it isn't always easy to add all of it. - seaellen

1 Answers

1
votes

Probable answer:

$completed = implode(",", $completed);
$sql = "UPDATE orders SET completed='1' WHERE completed=0 AND orders.id IN ($completed)"; 

assuming your $_POST['completed'] has ids of orders which are completed and completed column has only boolean values.