[PHP] array insert help
I need to create a form where work/home address details need to be entered. I'd like to have these listed as 2 entries in the mysql db so I'm assuming I need to create an array and loop through the array to do the insert. So I have an address[1] and address[2] for example for a total of 12 address fields in each set. (6 each) 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?? Any suggestions are greatly appreciated! Jason -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
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: bHome Address:/bbr / input type=text name=address[address][0] input type=text name=address[city][0] bWork Address:/bbr / 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/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] array insert help
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 paddress.$_POST['address']['address'][$i]; echo brcity.$_POST['address']['city'][$i]; } The form fields are as you suggested as well. Thanks again! Jason -Original Message- From: Ernest E Vogelsinger [mailto:[EMAIL PROTECTED] Sent: March 22, 2003 4:05 PM To: Jason Dulberg Cc: [EMAIL PROTECTED] 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: bHome Address:/bbr / input type=text name=address[address][0] input type=text name=address[city][0] bWork Address:/bbr / 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/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] array insert help
At 22:24 22.03.2003, Jason Dulberg said: [snip] 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 paddress.$_POST['address']['address'][$i]; echo brcity.$_POST['address']['city'][$i]; } [snip] Jason, I tried the following and it worked: form method=post bHome Address:/bbr / input type=text name=address[address][0] value=?php echo $_POST['address']['address'][0]; ? input type=text name=address[city][0] value=?php echo $_POST['address']['city'][0]; ? br / bWork Address:/bbr / input type=text name=address[address][1] value=?php echo $_POST['address']['address'][1]; ? input type=text name=address[city][1] value=?php echo $_POST['address']['city'][1]; ? br / input type=submit /form ?php for($i = 0; $i = 1; ++$i) { echo paddress $i: .$_POST['address']['address'][$i]; echo brcity $i: .$_POST['address']['city'][$i]; } -- O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php