View Single Post
Old 03-10-2011, 06:36 PM   PM User | #1
frank5050
New Coder

 
Join Date: Feb 2011
Posts: 32
Thanks: 3
Thanked 0 Times in 0 Posts
frank5050 is an unknown quantity at this point
Storing an unchecked checkbox value in mySQL

Hi

I have an array of checkboxes whose values if checked can be updated in mysql. The code I have below accomplishes that just fine.


On my form I have:

PHP Code:
print "<form method='post' action='update.php'>\n";

/////// mysQL query here

$myID $itemRow['myID'];
$chk =  $itemRow['item_shipped'] == 'checked' '';

echo 
"<input type=checkbox name=cbox[] value='{$itemRow['myID']}' $chk>"

echo
"</form>"

The above code displays various items with a checkbox next to them. So if that checkbox is checked the code below stores that in mysql.


On my update.php page I have:


PHP Code:

if(sizeof($_POST['cbox'])) {

//means if at least one check box is selected

foreach($_POST['cbox'] AS $id) { 

mysql_query("UPDATE om SET item_shipped ='1' WHERE myID=$id"); 
//end foreach

//end IF 



The problem is though i can check a checkbox and store that value '1' in mysql, I have no way of unchecking an already checked checkbox and storing the '0' in mysql.

Can anyone help?
Thanks in advance
frank5050 is offline   Reply With Quote