php_novice2007 Posted April 29, 2007 Share Posted April 29, 2007 Hi, This probably is really simple, but I'm kind of stuck... how do i use php to check if check boxes are clicked? So far I have <form name="myform" action="editViewUser1.php" method="POST"> Please select the unit number to toggle its public viewability: <br> <?php for($j=0; $j < count($unit_id); $j++) { print "<input type=checkbox name=$unit_id[$j]> $unit_id[$j]<br>"; } ?> <input type="Submit" name="a" value="Toggle Viewability"> </form> and for my processing part... foreach($unit_id as $unitNum) { if (isset($_POST['$unitNum'])) { echo "$unitNum is checked<br>"; } else { echo "$unitNum is not checked<br>"; } } right now my code says that none of my boxes are checked, even if i did check some... How shoud I do it? Thanks~! Link to comment https://forums.phpfreaks.com/topic/49153-solved-php-and-check-boxes/ Share on other sites More sharing options...
trq Posted April 29, 2007 Share Posted April 29, 2007 <?php foreach($_POST['$unitNum'] as $k => $v) { echo "$k was checked"; } ?> Boxes not checked will not be returned. Link to comment https://forums.phpfreaks.com/topic/49153-solved-php-and-check-boxes/#findComment-240869 Share on other sites More sharing options...
php_novice2007 Posted April 29, 2007 Author Share Posted April 29, 2007 It doesn't seem to work.. Notice: Undefined index: $unitNum in I:\webpages\editViewUser1.php on line 49 Warning: Invalid argument supplied for foreach() in I:\webpages\editViewUser1.php on line 49 The code: foreach($unit_id as $unitNum) { foreach($_POST['$unitNum'] as $k => $v) { echo "$k was checked"; } } Whats $v? Link to comment https://forums.phpfreaks.com/topic/49153-solved-php-and-check-boxes/#findComment-240876 Share on other sites More sharing options...
trq Posted April 29, 2007 Share Posted April 29, 2007 Remove the outer foreach() there is no such array as $init_id. Whats $v? Take a look at foreach(). Link to comment https://forums.phpfreaks.com/topic/49153-solved-php-and-check-boxes/#findComment-240878 Share on other sites More sharing options...
php_novice2007 Posted April 29, 2007 Author Share Posted April 29, 2007 Thanks, I fixed it by getting rid of the single quotes around $unitNum Link to comment https://forums.phpfreaks.com/topic/49153-solved-php-and-check-boxes/#findComment-240886 Share on other sites More sharing options...
trq Posted April 29, 2007 Share Posted April 29, 2007 Um yeah... my mistake. Link to comment https://forums.phpfreaks.com/topic/49153-solved-php-and-check-boxes/#findComment-240897 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.