How to collect Checkbox Array values?
Posted by
om 3 April, 2009
Beginner PHP Programmer always searches for easy way to collect Checkbox data from forms.
Here in this post I have used 3-4 lines of easy code to collect data from multi checkboxes. Instead of using several table-fields you can store your comma separated data in on field of the table. This is easy and handy.
View Code LANGUAGE
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | <?php
$name_box = $_REQUEST["name_box"];
while (list ($key_check,$val_check) = @each ($name_box))
{
$value_check .= $val_check.",";
}
$all_value_check = substr($value_check, 0, -1);
echo $all_value_check;
?>
<form method="post">
<table style="border-collapse: collapse" border="0" cellspacing="0" width="100">
<tbody>
<tr bgcolor="#ffffff">
<td width="25%">
<input name="name_box[]" type="checkbox" value="Om" /></td>
<td width="25%"> Om</td>
<td width="25%">
<input name="name_box[]" type="checkbox" value="Jyoti" /></td>
<td width="25%"> Jyoti</td>
<td width="25%">
<input name="name_box[]" type="checkbox" value="Bruce" /></td>
<td width="25%"> Bruce</td>
</tr>
<tr bgcolor="#f1f1f1">
<td width="25%">
<input name="name_box[]" type="checkbox" value="Yaling" /></td>
<td width="25%"> Yaling</td>
<td width="25%">
<input name="name_box[]" type="checkbox" value="Angelica" /></td>
<td width="25%"> Angelica</td>
<td width="25%">
<input name="name_box[]" type="checkbox" value="Tara" /></td>
<td width="25%"> Tara</td>
</tr>
<tr>
<td colspan="6" align="center">
<input type="submit" value="Select" /></td>
</tr>
</tbody></table>
</form> |
Categories :
PHP

How can I get the data back out of the database and recheck the boxes for that it has stored. I need to do this to create an update form.
Thanks