Page 1 of 1

Using superglobals in conditionals

Posted: Tue Jan 27, 2009 12:05 am
by iG9
I'm trying this:

Code: Select all

 
if ($_GET["variable"]) {
    #code...
}
 
But I get an infinite loop and an error about an undefined index. Am I not allowed to do this?
Thanks in advance.

Re: Using superglobals in conditionals

Posted: Tue Jan 27, 2009 12:18 am
by Christopher
I doubt that you get an infinite loop, and you actually get a warning not an error about an undefined index. Do this:

Code: Select all

if (isset($_GET["variable"]) && $_GET["variable"]) {
    #code...
}

Re: Using superglobals in conditionals

Posted: Tue Jan 27, 2009 12:27 am
by iG9
Thanks, I'll try it. I said infinite loop because the page never stops loading until I hit the stop button. It hangs Safari entirely and I have to kill it. Opera at least stops loading when I tell it to. The message I get is:

Notice: Undefined index: title in /Library/WebServer/Documents/insert.php on line 36

I don't know if that's an error or a warning.
Anyway thanks for the code, I'll try it and report back.

Re: Using superglobals in conditionals

Posted: Tue Jan 27, 2009 2:25 am
by iG9
Got it working. The loop was caused by a different part of the code, so you were right to be skeptical. Thanks again. :D