Posted by mountain.dog@gmail.com on 03/29/07 14:12
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_array($result))...
<input name="menu_show_attribute[]" type="checkbox"
class="checkbox"');
if ($row['menu_show_attribute'] == 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_show_attribute); $i++) {
if (isset($menu_id) == 'checked') {
$menu_show_attribute = 1;
} elseif ($menu_show_attribute != 'checked') {
$menu_show_attribute = 0;
}
$query = 'UPDATE menu SET menu_show_attribute = "'.
$menu_show_attribute.'" WHERE menu_id = "'.
$menu_show_attribute[$i].'"';
echo("<br>");
echo $query;
$result = mysql_query($query, $db) or die(mysql_error());
}
Navigation:
[Reply to this message]
|