Can somebody help me? i cant echo my checkbox group with a multiple selection. Every time i echo the checkbox group the only things show is the last box that Ive check.
here's my code
<?php
$submit = $_POST['submit'];
$incharge = $_POST['incharge'];
if ($submit)
{
echo $incharge;
}
?>
<table width="500" height="69">
<tr>
<td width="73"><label>
<input type="checkbox" name="incharge" value="1" id="responsible_0" />
MNFA</label></td>
<td width="72"><label>
<input type="checkbox" name="incharge" value="2" id="responsible_1" />
HJB</label></td>
<td width="70"><label>
<input type="checkbox" name="incharge" value="3" id="responsible_2" />
JBG</label></td>
<td width="75"><label>
<input type="checkbox" name="incharge" value="4" id="responsible_3" />
MSG</label></td>
<td width="275"><label>
<input type="checkbox" name="incharge" value="5" id="responsible_4" />
MGR</label></td>
</tr>
<tr>
<td height="33"><label>
<input type="checkbox" name="incharge" value="6" 开发者_StackOverflow社区id="responsible_5" />
AAP</label></td>
<td><label>
<input type="checkbox" name="incharge" value="7" id="responsible_6" />
EPM</label></td>
<td><label>
<input type="checkbox" name="incharge" value="8" id="responsible_7" />
SGA</label></td>
<td><label>
<input type="checkbox" name="incharge" value="9" id="responsible_8" />
JLL</label></td>
<td><label>
<input type="checkbox" name="incharge" value="10" id="responsible_9" />
AFM</label></td>
</tr>
</table>
Thank you in advance.. .
Change the name attribute to:
name="incharge[]"
That will produce an array, $incharge.
Note that you won't be able to just echo that value; you will need to "print_r" or loop through it.
You need to change the "name" attribute of your "input" elements to indicate that it's an array by adding square brackets []
at the end. $_POST['incharge']
will be an array instead of a string.
Example
<input type="checkbox" name="incharge[]" value="1" id="responsible_0" />
The reason only the last value is being sent is because all the checkboxes have the same name, thereby renaming them over and over. What you want is to assign all the checkboxes to an array, like so:
Change name="incharge"
to name="incharge[]"
You'll then want to iterate it:
if ($submit)
{
// PHP throws a fit if we try to loop a non-array
if(is_array($incharge))
{
foreach($incharge as $val)
{
echo $val . '<br />';
}
}
}
if(isset($_post['calculations'])
{
$member = $_POST['member'];//get the total values in an array
if(is_array($member))// confirm $member is an array
{
foreach($member as $names)
{
echo $names ."<br/>";//take the values
}
}
<input type="checkbox" name="member[]" value="value1">
精彩评论