RE: [PHP] array insert help

From: Date: Sat, 22 Mar 2003 21:24:55 +0000
Subject: RE: [PHP] array insert help
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-140712@lists.php.net to get a copy of this message
Thanks for your help... I tried the code as you suggested however when I attempted to echo the variables for testing but nothing showed. for($i = 0; $i <= 1; ++$i) { echo "<p>address".$_POST['address']['address'][$i]; echo "<br>city".$_POST['address']['city'][$i]; } The form fields are as you suggested as well. Thanks again! Jason > -----Original Message----- > From: Ernest E Vogelsinger [mailto:ernest@vogelsinger.at] > Sent: March 22, 2003 4:05 PM > To: Jason Dulberg > Cc: php-general@lists.php.net > Subject: Re: [PHP] array insert help > > > At 20:59 22.03.2003, Jason Dulberg said: > --------------------[snip]-------------------- > >My problem is that I'm not sure how to set up the array for the > fields and > >how to take the input fields and insert them. Do I need a > multidimensional > >array for this? > > > >ie. > ><input type="text" name="address[address][]"> > ><input type="text" name="address[city][]"> > > > >How would I decode that to create an insert statement?? > --------------------[snip]-------------------- > > I believe your example would work. However since you have a > definite number > of adresses you could add the index directly, as here: > > <b>Home Address:</b><br /> > <input type="text" name="address[address][0]"> > <input type="text" name="address[city][0]"> > > <b>Work Address:</b><br /> > <input type="text" name="address[address][1]"> > <input type="text" name="address[city][1]"> > > When the form is received you will have an array for adress that > looks like > this: > > $_REQUEST['address'] = array( > 'address' => array(0 => 'home address', 1 => 'work > address'), > 'city' => array(0 => 'home city', 1 => 'work > city')); > > To insert the home address you'd create an SQL statement like this: > > for($i = 0; $i <= $number_of_addresses; ++$i) { > $sql = "insert into address(adress, city) values (" . > "{$_REQUEST['address']['address'][$i]}," . > "{$_REQUEST['address']['city'][$i]})"; > // more code > } > > Hope this helps, > > -- > >O Ernest E. Vogelsinger > (\) ICQ #13394035 > ^ http://www.vogelsinger.at/ > >

« previous php.general (#140712) next »