Re: Accessing variables from a form

From: Date: Wed, 21 Feb 2001 17:07:54 +0000
Subject: Re: Accessing variables from a form
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-41000@lists.php.net to get a copy of this message
ok here we are, your code is *almost* correct, but even syntaxialy correct doesnt mean it should be used :) use arrays, its a tone easier. to fix your code change $name =& $field; to $name = $$field; now to make the code, a ton easier to use, use arrays. <?php ... echo " <input type=text name=name[$people_id] value='somedata'> "; ... ?> <?php ... foreach($name as $pos => $val) { echo $val; } ... ?> arrays are great things, use them lost :) haha -- Chris Lee Mediawaveonline.com em. lee@mediawaveonline.com ph. 250.377.1095 ph. 250.376.2690 fx. 250.554.1120 "Don" <don@lclcan.com> wrote in message news:3A93F047.F3230950@lclcan.com... > Hi, > > I'm in a quandary here. I have a form which contains sever tables each > containing similar fields. The number of tables are dynamic based on > vales I retrieve from a database. Each table has the following fields: > > $name > $phone > $fax > > In order to differentiate the filed names in my form, I created a loop > and extended each field name with the loop iteration as such ($rownum is > my loop counter): > > <snip> > <input type="text" name="name" . $rownum . ">" > <input type="text" name="phone" . $rownum . ">" > <input type="text" name="fax" . $rownum . ">" > > So I would have field variables of: > $name1, $name2, $name3, ... > $phone1, $phone2, $phone3, ... > $fax1, $fax2, $fax3, ... > > So far so good as I have verified that these fields exist. > > Now, when the user clicks on the submit button, the form data gets > posted to a PHP script. I wish to access the variables but here I am at > a loss. I attempted the following code without success ($rownum is the > number of tables I created): > > for ($i = 1; $i <= $rownum; $i++) { > $field = "phone" . $i; > $name =& $field; > echo $field . ":" . $name . "\n"; > } > > The docs state that references are NOT pointers. So....., how can I > access my variables? I could not find any information on Macros or > Pointers. > > Thanks, > Don > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#41000) next »