...

View Full Version : working with checkboxes



golffor1
02-17-2012, 03:05 AM
I have the following code

<td width = '2%' height="40"> <div align="center"><input type="checkbox" name="checkbox[]" value="<?PHP $rows['player_number']; ?>"></div></td>

on one page

then on the second page I have



<?php
$aDoor = $_POST['checkbox'];
if(empty($aDoor))
{
echo("You didn't select any buildings.");
}
else
{
$N = count($aDoor);
echo("You selected $N door(s): ");
for($i=0; $i < $N; $i++)
{
echo($aDoor[$i] . " ");
}
}

foreach ($aDoor as $statename)
{

echo "$statename is checked";
}

if($aDoor){
foreach($aDoor AS $sID => $sValue){
//Here you can process each posted value separately
echo "Checkbox with value ".$sValue." was checked!<br>";
}
}

foreach($_POST['checkbox'] as $value) {

echo "Checked: $value\n";


}


if(!empty($_POST['checkbox'])){

for ($i=0; $i < count($_POST['checkbox']);$i++) {

echo $_POST['checkbox'][$i] . ", ";

}

}

foreach ( ( array ) $_POST['checkbox'] as $value )

{

// do whatever the crap you want with $value

echo $value;

}


if (count($_POST) > 0) {
echo '<pre>'; print_r($_POST); echo '</pre>';
}

if(isset($_POST['submit']))
{
$compare = $_POST["checkbox"];
echo '<h2>Checkbox values:</h2>';
foreach ($compare as $value)
echo $value."<br />";
}



?>

The problem I have is that I can't see what is passed with each checkbox. I have tried to the examples in the php code and nothing seems to work. Can you help me with figuring out this problem?

I am using a while loop so there is a chance I could have 1 row or 100 rows. I click the checkbox and then send to the second page. I can't see the values on the second page.

golffor1
02-17-2012, 03:29 AM
I don't know what I did...but it is fixed now with the following code



name="checkbox[]" value="<?PHP echo $rows['player_number']; ?>"></div></td>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum