Prev: file_get_contents limit
Next: form validation code
From: "Ford, Mike" on 30 Jun 2010 09:15 > -----Original Message----- > From: Ron Piggott [mailto:ron.piggott(a)actsministries.org] > Sent: 29 June 2010 22:22 > > Am I on the right track? I don't know what to do with the second > "FOREACH" Sort of. > > <?php > > foreach($_REQUEST as $key => $val) { > $$key = $val; > echo $key . ": " . $val . "<br>"; > > if ( $val == "Array" ) { I would prefer to use is_array() here: if (is_array($val)) > $i=0; > At this point, you've just proved that $val is an array (whichever test you use!), so simply foreach it like one. I know you know how to do that as you did it with $_REQUEST above! > foreach ($val) { > echo "$val[$i]<br>"; > $i++; > } foreach ($val as $option) { echo "$option<br />\n"; } > > } > } > > ?> Cheers! Mike -- Mike Ford, Electronic Information Developer, Libraries and Learning Innovation, Leeds Metropolitan University, C507, Civic Quarter Campus, Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom Email: m.ford(a)leedsmet.ac.uk Tel: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm
From: tedd on 30 Jun 2010 09:58
At 4:54 PM -0400 6/29/10, Ron Piggott wrote: >I am trying to process a form where the user uses checkboxes: > ><input type="checkbox" name="painDesc[]" value="1" />Sharp ><input type="checkbox" name="painDesc[]" value="2" />Stabbing ><input type="checkbox" name="painDesc[]" value="3" />Jabbing > >When I do: > >foreach($_REQUEST as $key => $val) { > $$key = $val; > echo $key . ": " . $val . "<br>"; >} > >The output is: > >painDesc: Array > >I need to know the values of the array (IE to know what the user is >checking), not that there is an array. I hope to save these values to the >database. > >Thank you. > >Ron Ron: Try this: http://php1.net/b/form-checkbox/ If you want the form to retain the values, try this: http://php1.net/b/form-checkbox1/ Cheers, tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com |