Jump to content

[SOLVED] php and check boxes


php_novice2007

Recommended Posts

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

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.