gardan06 Posted October 10, 2006 Share Posted October 10, 2006 im having a hard time getting checkbox values using php. can anyone help me? Link to comment https://forums.phpfreaks.com/topic/23505-form-post-checkbox-values/ Share on other sites More sharing options...
php_coder_dvo Posted October 10, 2006 Share Posted October 10, 2006 can you give more details??? Link to comment https://forums.phpfreaks.com/topic/23505-form-post-checkbox-values/#findComment-106655 Share on other sites More sharing options...
gardan06 Posted October 10, 2006 Author Share Posted October 10, 2006 im testing getting checkbox values. here is test.php:[quote]<form method="post" name="form1" action="test2.php">Likes: <p><input type="checkbox" name="like[]" value="mustard" />Mustard<br /><input type="checkbox" name="like[]" value="broccoli" />Broccoli<br /><input type="checkbox" name="like[]" value="women" />Women<br /><input type="checkbox" name="like[]" value="men" />Men<br /><input type="checkbox" name="like[]" value="catsup" />Catsup<br /><input type="checkbox" name="like[]" value="magazine" />Magazines<br /><p><input type="submit" value="Submit"></form>[/quote]and this is test2.php:[quote]<? $ctr = count($_POST['like']); //echo "count = ".$ctr."<p>";//die(); $like = array(); for ($i=0;$i<5;$i++) { echo "post = ".$_POST['like'.$i]."<br>"; }?>[/quote] Link to comment https://forums.phpfreaks.com/topic/23505-form-post-checkbox-values/#findComment-106657 Share on other sites More sharing options...
gardan06 Posted October 10, 2006 Author Share Posted October 10, 2006 nvm, i got it :) Link to comment https://forums.phpfreaks.com/topic/23505-form-post-checkbox-values/#findComment-106658 Share on other sites More sharing options...
wildteen88 Posted October 10, 2006 Share Posted October 10, 2006 Rather than using a for loop it'll be better if you use a foreach loop:[code=php:0]foreach($_POST['like'] as $key => $value){ echo "post = " . $value;}[/code] Link to comment https://forums.phpfreaks.com/topic/23505-form-post-checkbox-values/#findComment-106721 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.