Re: HTTP_POST_VARS gives odd results
| From: | Ignacio Vazquez-Abrams | Date: | Tue, 28 Nov 2000 16:56:19 +0000 |
| Subject: | Re: HTTP_POST_VARS gives odd results | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-27620@lists.php.net to get a copy of this message | ||
On Tue, 28 Nov 2000, Janet Valade wrote:
> I have the following code which doesn't seem to give me the results I
> expect.
>
> if ($testvar == "other") {
> $newvalue1="string1";
> $newvalue2="string2";
> $HTTP_POST_VARS[addr] = $newvalue1;
> $HTTP_POST_VARS[city] = $newvalue2;
> }
>
> reset($HTTP_POST_VARS);
>
> while (list($key,$value) = each($HTTP_POST_VARS)) {
> echo "key, value = $key, $value<Br>";
>
> if (empty($$key) ) {
> do stuff;
> else
> do other stuff;
> }
> }
>
> The above while loop works perfectly without the code before it. However,
> when I add the code before it that changes the values of some of the
> elements in HTTP_POST_VARS, it no longer works. The values were changed
> successfully, the echo in the loop shows the correct changed values of
> string1 and string2 for $key,$value. However, when it gets to the if (empty)
> statement, it is evaluated as empty (its previous value) and do stuff is
> done, rather than do other stuff. The elements of HTTP_POST_VARS that were
> not changed still are evaluated correctly by the if empty statement; only
> the changed elements are evaluated incorrectly. Clearly, I am not
> understanding something about HTTP_POST_VARS. Can someone tell me what I am
> doing wrong?
>
> Janet
>
When register_globals is on, anything that comes through $HTTP_*_VARS is
registered as global only once when the script starts. Anything that gets
assigned to the arrays after the script starts is ignored.
Quick question:
Why do you even have if(empty($$key)) in there? Why don't you just use
if(empty($val))?
--
Ignacio Vazquez-Abrams <ignacio@openservices.net>