Using superglobals in conditionals

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
iG9
Forum Commoner
Posts: 38
Joined: Fri Jul 18, 2008 2:11 pm

Using superglobals in conditionals

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Using superglobals in conditionals

Post 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...
}
(#10850)
iG9
Forum Commoner
Posts: 38
Joined: Fri Jul 18, 2008 2:11 pm

Re: Using superglobals in conditionals

Post 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.
iG9
Forum Commoner
Posts: 38
Joined: Fri Jul 18, 2008 2:11 pm

Re: Using superglobals in conditionals

Post 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
Post Reply