You are here: Re: Retrieving the multiple values set by a form « PHP Programming Language « IT news, forums, messages
Re: Retrieving the multiple values set by a form

Posted by Jerry Stuckle on 11/28/09 11:59

Ron Barnett wrote:
> "Girish" <girishbhat6620@gmail.com> wrote in message
> news:1159359055.574104.168360@h48g2000cwc.googlegroups.com...
>
>>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@attglobal.net
==================

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация