Remove $_POST from $_POST[firstname][$key], $_POST[middlename][$key] and
$_POST[lastname][$key].
It should simply be $firstname[$key], $middlename[$key], and $lastname[$key]
Not sure what your array data looks like but instead of using while() use
foreach():
foreach($_POST['firstname'] as $key => $value){
$firstname[$key] = trim($_POST[firstname][$key]);
$middlename[$key] = trim($_POST[middlename][$key]);
$lastname[$key] = trim($_POST[lastname][$key]);
}
-----Original Message-----
From: Ian M. Evans [mailto:[EMAIL PROTECTED]
Sent: Tuesday, August 17, 2004 2:35 PM
To: [EMAIL PROTECTED]
Subject: [PHP] getting an array out of the POST array
One day I need to take a vacation with a big pot of coffee and study arrays.
They're
my downfall.
We're moving to a new server and finally have a recent version of PHP.
We have a page on the site for captioning the photos with the names of the
subjects.
After the form is posted, the script would do a bunch of things on the
names, then
insert them:
while (list ($key, $val) = each ($firstname)) {
$firstname[$key] = trim($firstname[$key]);
$middlename[$key] = trim($middlename[$key]);
$lastname[$key] = trim($lastname[$key]);
...etc...
Now that we have a newer version of PHP, we have the $_POST variables, so
the
$firstname $middlename $lastname arrays are tossed into the $_POST array.
I figured that it would change the above to:
while (list ($key, $val) = each ($_POST[firstname])){
$_POST[firstname][$key] = trim($_POST[firstname][$key]);
$_POST[middlename][$key] = trim($_POST[middlename][$key]);
$_POST[lastname][$key] = trim($_POST[lastname][$key]);
When I inserted that into the database I, of course ended up with the name:
"Array[0] Array[0] Array[0]"
How the heck do I get the name arrays out of the $_POST arrays?
Many thanks.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php