jimot
Nov 28th, 2005, 07:15 PM
hi all.. how can we check if at least one of the checkboxes in a form is checked?
Here is the problem, I have a form with checkboxes. If at least one of the boxes is checked, then there's no problem after I press the submit button (delete), but if no boxes are checked, then it gives me an error.
here's my code in the index.php:
print "<form action=delete.php><table>";
while (list($code, $url, $categori, $description) = mysql_fetch_row($result)):
print "<tr><td><input type=checkbox name=item[$code] value=y>$description
</td></tr>";
endwhile;
print "<tr><td><input type=submit value=Delete></td></tr>";
print "</table></form>";
and here's the code in delete.php:
while (list($key, $val) = each ($item)) :
if ($val == "y"):
$query = "DELETE FROM items WHERE code = $key";
$result = mysql_query($query);
endif;
endwhile;
if none of the checkboxes is checked, then it gives this error:
Warning: Variable passed to each() is not an array or object in /home/www/dl.jimotman.com/index.php on line 100
Here is the problem, I have a form with checkboxes. If at least one of the boxes is checked, then there's no problem after I press the submit button (delete), but if no boxes are checked, then it gives me an error.
here's my code in the index.php:
print "<form action=delete.php><table>";
while (list($code, $url, $categori, $description) = mysql_fetch_row($result)):
print "<tr><td><input type=checkbox name=item[$code] value=y>$description
</td></tr>";
endwhile;
print "<tr><td><input type=submit value=Delete></td></tr>";
print "</table></form>";
and here's the code in delete.php:
while (list($key, $val) = each ($item)) :
if ($val == "y"):
$query = "DELETE FROM items WHERE code = $key";
$result = mysql_query($query);
endif;
endwhile;
if none of the checkboxes is checked, then it gives this error:
Warning: Variable passed to each() is not an array or object in /home/www/dl.jimotman.com/index.php on line 100