Re: array $_POST problem

From: Date: Tue, 16 Mar 2004 18:16:46 +0000
Subject: Re: array $_POST problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-180579@lists.php.net to get a copy of this message
You're the Joey Kelly who runs the LUG in NoLA, yes? > I've got a sticky problem that I need to solve. I've just turned on > register_globals in my PHP php.ini file, and therefore have to run my form > variables through $_POST: > $variable = $_POST[$variable]; > echo $variable; Or you can use extract(); > The problem I'm having is that the script Im trying to refactor worked great > before I turned register_globals off. The script posts an array, and I can't > seem to figure out how to $_POST the array. It seems like the array is posted just fine. > In both cases, changing the extension from .php to .phps shows you the source > code. As you can see, above the form I've tried several attempts to access > the data, all of which seem to fail. How is it failing? Looking at the source, you are definitely on the right track. > My question: What am I doing wrong? I suspect that I'm having trouble with > nested arrays, etc.. The thing that bothers me is that the data is available > (see the array printout at the bottom?). Upon post, you need to get materials as such: $materials = &$_POST['materials']; to list out the quantity, you can do any the following: foreach( $materials['quantity'] as $quantity ) { echo $quantity . '<br>'; } foreach( $materials['description'] as $description ) { echo $description . '<br>'; } for( $i = 0; $i < 5; $i++ ) { echo $materials['description'][$i] . '::' . $materials['quantity'][$i] . '<br>'; } Personally, I'd rename your form elements to: $materials[$item][quantity] $materials[$item][price] $materials[$item][description] Chris

« previous php.general (#180579) next »