Re: parse form input

From: Date: Wed, 31 Jan 2001 03:46:10 +0000
Subject: Re: parse form input
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-37398@lists.php.net to get a copy of this message
On Wed, 31 Jan 2001 01:55, Robert wrote: > > variables passed from form = > part=68030&quan=500&I=x&part=68040&quan=350&I=x&sid=6754g543a76 I am > sending several part numbers from the form, but when parsed it only gives > me the last one How do I get it to return all of the parts? I'm a PHP > newbie, only been programming for 2 weeks... > > <script language="php" > $i=0; > if(!is_array($HTTP_POST_VARS)) > return; > reset($HTTP_POST_VARS); > while(list($key,$val)= each($HTTP_POST_VARS)){ > $GLOBAL[$key]= $val; > $val=stripslashes($val); > if ($key =="I"){$message=$message. "_________________________\n";} > //<---Divide parts into individual sections if ($key !="sid" ){if ($key > !="I"){$message=$message. "$key = $val\n";}} //<---Add to > message unless key is sid echo $key " = " $val; > } > </script> > > Thanks for any help You'll need to treat the part and quan variables as arrays - in the form the user fills in they would need to be named as form[] and quan[] Then at the receiving end you could check the number of elements in the array with count($varname) and proceed according to the result; ie if it's zero, there is nothing to do/an error has been made; if one, just grab the value of the variable ; or if >1, cycle through the elements of the array(s) and do what you need. -- David Robley | WEBMASTER & Mail List Admin RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/ AusEinet | http://auseinet.flinders.edu.au/ Flinders University, ADELAIDE, SOUTH AUSTRALIA

« previous php.general (#37398) next »