Click to See Complete Forum and Search --> : Checking predefined variable indexes


Exuro
08-09-2003, 10:33 PM
Okay, I've written a few PHP scripts and most of them either involve $_POST, $_GET, or $_COOKIE. Unfortunately, sometimes the index I'm using in the script isn't defined... Like if the user has cookies disabled, or they bookmarked the page and didn't submit the form to get there. So, when this happens PHP throws an error at me saying that the index is undefined or something like that. It would be nice to be able to test to see if an index exists before a script involving it is run, but I haven't been able to find a way to do that. Can anyone help me with this? Thanks!

pyro
08-09-2003, 10:35 PM
You need to use isset() (http://us4.php.net/manual/en/function.isset.php), something like this:

if (isset($_POST["test"])) {
#if the POST variable "test" is set...
}

Exuro
08-09-2003, 10:48 PM
Thanks pyro!

pyro
08-09-2003, 10:52 PM
You bet... :)