Re: $HTTP_GET_VARS
| From: | Matt | Date: | Fri, 17 Jan 2003 22:51:31 +0000 |
| Subject: | Re: $HTTP_GET_VARS | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-132051@lists.php.net to get a copy of this message | ||
----- Original Message -----
From: "Mike Tuller" <php@ce.anoka.k12.mn.us>
To: "php mailing list" <php-general@lists.php.net>
Sent: Friday, January 17, 2003 5:05 PM
Subject: [PHP] $HTTP_GET_VARS
> I am following an example in a book and have run into a problem with a
> script that I am trying to run under PHP 4.3.0. What I have is a page
> that you click on an id number that is from a listing in a database,
> and it is supposed to take you to a page to edit that item. I have the
> id sent in the url (http://127.0.0.1/asset/editasset.php?id=3) and the
> book says to use $HTTP_GET_VARS to take that id
Are you using $HTTP_GET_VARS['id']? If it's in a function, then php scopes
$HTTP_GET_VARS as a local variable, and thus there's nothing in it. While
that's different then most other programming languages, it's how it is in
php. If you want to reference the global $HTTP_GET_VARS in a function, then
you must 'global' it:
function foo() {
global $HTTP_GET_VARS;
echo "Id is {$HTTP_GET_VARS['id']}<br>\n";
}
Now the php developers added a new set of arrays to help with that in 4.1.2
(I think), so use $_GET['id'] which always references the builtin global
$_GET array. It's better.
i.e. Learn the new way and not the old way ...