Jump to content


Photo

form post checkbox values


  • Please log in to reply
4 replies to this topic

#1 gardan06

gardan06
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 10 October 2006 - 06:15 AM

im having a hard time getting checkbox values using php. can anyone help me?

#2 php_coder_dvo

php_coder_dvo
  • Members
  • PipPip
  • Member
  • 18 posts
  • LocationPhilippines

Posted 10 October 2006 - 06:29 AM

can you give more details???

#3 gardan06

gardan06
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 10 October 2006 - 06:31 AM

im testing getting checkbox values. here is test.php:

<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>


and this is test2.php:

<?
$ctr = count($_POST['like']);
//echo "count = ".$ctr."<p>";//die();
$like = array();
for ($i=0;$i<5;$i++) {
echo "post = ".$_POST['like'.$i]."<br>";
}
?>



#4 gardan06

gardan06
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 10 October 2006 - 06:36 AM

nvm, i got it :)

#5 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 10 October 2006 - 10:32 AM

Rather than using a for loop it'll be better if you use a foreach loop:

foreach($_POST['like'] as $key => $value)
{
    echo "post = " . $value;
}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users