I have a query that shows a list of options that a user can toggle on
or off using a checkbox.
query...
form...
while($row = mysql_fetch_arr ay($result))...
<input name="menu_show _attribute[]" type="checkbox"
class="checkbox "');
if ($row['menu_show_attr ibute'] == 1) {
echo (' value="'.$row[menu_id].'" checked />
} else {
echo (' value="'.$row[menu_id].'" />');
}
The list is generated from boolean values in a DB. This populates my
form with checkboxes, some are checked and others are not. I'm using
an if statement to sort it (checked). This works fine.
The problem is when the user un-checks a checkbox, the value does not
get passed and the DB does not update - set/change it to 0. The only
values that get passed are the checkboxes that are checked. Below is
the query / code after the submit button has been pressed. Are radio
buttons the answer? Any help / suggestions would be very much
appreciated.
//process form
for ($i = 0; $i < count($menu_sho w_attribute); $i++) {
if (isset($menu_id ) == 'checked') {
$menu_show_attr ibute = 1;
} elseif ($menu_show_att ribute != 'checked') {
$menu_show_attr ibute = 0;
}
$query = 'UPDATE menu SET menu_show_attri bute = "'.
$menu_show_attr ibute.'" WHERE menu_id = "'.
$menu_show_attr ibute[$i].'"';
echo("<br>");
echo $query;
$result = mysql_query($qu ery, $db) or die(mysql_error ());
}
or off using a checkbox.
query...
form...
while($row = mysql_fetch_arr ay($result))...
<input name="menu_show _attribute[]" type="checkbox"
class="checkbox "');
if ($row['menu_show_attr ibute'] == 1) {
echo (' value="'.$row[menu_id].'" checked />
} else {
echo (' value="'.$row[menu_id].'" />');
}
The list is generated from boolean values in a DB. This populates my
form with checkboxes, some are checked and others are not. I'm using
an if statement to sort it (checked). This works fine.
The problem is when the user un-checks a checkbox, the value does not
get passed and the DB does not update - set/change it to 0. The only
values that get passed are the checkboxes that are checked. Below is
the query / code after the submit button has been pressed. Are radio
buttons the answer? Any help / suggestions would be very much
appreciated.
//process form
for ($i = 0; $i < count($menu_sho w_attribute); $i++) {
if (isset($menu_id ) == 'checked') {
$menu_show_attr ibute = 1;
} elseif ($menu_show_att ribute != 'checked') {
$menu_show_attr ibute = 0;
}
$query = 'UPDATE menu SET menu_show_attri bute = "'.
$menu_show_attr ibute.'" WHERE menu_id = "'.
$menu_show_attr ibute[$i].'"';
echo("<br>");
echo $query;
$result = mysql_query($qu ery, $db) or die(mysql_error ());
}
Comment