On Fri, Jul 12, 2002 at 10:59:00PM -0400, Blue Presley wrote: > Hello. I have a form that I would like to use checkboxes. > ... snip ... > I've been told that if I want to manipulate each > one then I should use 'name=checkbox[]' and make an array out of it. okay, > fine. but how do i access them in my PHP script? I know I have to use the > $_POST[] array, but this creates a multidiminsional array, yes? do i access > it like $_POST[checkbox[1]]?? or $_POST[checkbox][1]??
The latter. But note, if a box isn't checked, it's not going to be sent, so won't be in the array. <form> <input type="checkbox" name="StateID[]" value="32" /> NV <input type="checkbox" name="StateID[]" value="33" checked /> NH <input type="checkbox" name="StateID[]" value="34" checked /> NJ </form> In this case $_POST['checkbox'][0] would be 33 and ...[1] would be 34. Sometimes it's handy to identify the key upfront: <form> <input type="checkbox" name="StateID[32]" value="608" /> NV <input type="checkbox" name="StateID[33]" value="2" /> NH <input type="checkbox" name="StateID[34]" value="40" checked /> NJ </form> That would yield $_POST['checkbox']['34'] = 40. A nice way to handle incomming checkboxes is this: while ( list($Key, $Val) = each($checkbox) ) { # do what you need to do... # for example, show what was sent... echo "<br />$Key = $Val\n"; } Enjoy, --Dan -- PHP classes that make web design easier SQL Solution | Layout Solution | Form Solution sqlsolution.info | layoutsolution.info | formsolution.info T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php