When posting PHP code, please use the board's [noparse]
..
[/noparse] bbcode tags as they make your code much easier to read and analyze. Also, welcome to PHPBuilder!
As for your issue, your if() statement doesn't make much sense. You're testing to see if a variable is defined, and yet you just defined it a couple of lines before the if() statement. In other words, you might as well be testing to see if 1 + 2 == 3.