Re: Retrieving the multiple values set by a form



Ron Barnett wrote:
"Girish" <girishbhat6620@xxxxxxxxx> wrote in message news:1159359055.574104.168360@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Hi Everyone,

I am passing a form to a php script for further processing.


I am able to retrieve the last value set for that given form variable
using
$variable=$_REQUEST['form_variable'];


My question is, what is the Php way of retrieving all the values passed
for the same form variable?

For example, if the php script is called with a syntax like

http://xxxx/get_variables.php?form_variable=value1&form_variable=value2&form_variable=variable


, how do I iterate through all the values that form_variable has been
set to?

Thanks and regards,
Girish


Hi Girish,

In the example you have given, which equates to a Get, the variables will indeed overwrite each other with only the last value surviving, as stated by lorento.

You can however create an array by suffixing the variable name (in the HTML form) this
<input name='inp[0]' type='hidden' value='first value'>
<input name='inp[1]' type='hidden' value='second value'>
<input name='inp[2]' type='hidden' value='third value'>

once this is received by your PHP script the values may be retrieved :

$myArray = $_REQUEST('ip'); // note no subscripts required

$myArray['0'] will contain 'first value', $myArray['1'] the second value, and so on

BTW Register globals should be OFF on any production machine so there is little point in having it on in a development machine.

HTH

Ron



Actually, it's even easier than that. No need to specify the index when you're using the default.

<input name='inp[]' type='hidden' value='first value'>
<input name='inp[]' type='hidden' value='second value'>
<input name='inp[]' type='hidden' value='third value'>

inp[0] == 'first value'
inp[1] == 'second value'
inp[2] == 'third value'

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
.



Relevant Pages

  • Re: [PHP] retrieve POST body?
    ... Reading from php://input on a webserver will retrieve the Body of the ... HTTP Request. ... Is there any way to retrieve the POST message body when a form is ... PHP script has to be able to handle forms with file uploads. ...
    (php.general)
  • Re: Retrieving the multiple values set by a form
    ... I am passing a form to a php script for further processing. ... I am able to retrieve the last value set for that given form variable ... BTW Register globals should be OFF on any production machine so there is ...
    (comp.lang.php)
  • HttpWebRequest - HttpWebResponse: incomplete reply
    ... i have to retrieve the output of a php script on a remote apache web ... server. ... accessing that php script through code, i always get an incomplete result ...
    (microsoft.public.dotnet.framework)
  • Re: How can I increase the shells (or specific applications) memory limit?
    ... assign more memory to a PHP script running in a shell and/or in a browser.. ... I'm building a PHP script that has to retrieve pretty large sets of data ... quickly runs out of memory. ... the script still bails out with a memory limit ...
    (freebsd-questions)