checking to see if global variable exists

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
nutstretch
Forum Contributor
Posts: 104
Joined: Sun Jan 11, 2004 11:46 am
Location: Leicester

checking to see if global variable exists

Post by nutstretch »

Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I am trying to see if a global variable exists and if it doesn't I want to create one.  

the code i have used on my test page is:

Code: Select all

hello world
<?php

if (empty($_REQUEST['VendorTxCode'] == true) 
{
$ThisVendorTxcode = $today.(rand(0,32000)*rand(0,32000));
print "new ".$ThisVendorTxCode;
}
else
{
$ThisVendorTxcode = $_REQUEST['VendorTxCode'];
print $ThisVendorTxCode;
}
?>
This page is showing up blank. Please can someone see a or several fatal flaws for me. NOt even the hello world is showing

Thanks in anticipation

Nuts


Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

you missed a paren in your if clause
User avatar
aerodromoi
Forum Contributor
Posts: 230
Joined: Sun May 07, 2006 5:21 am

Post by aerodromoi »

As empty returns only true/false you could also save a few bytes by using

Code: Select all

if(empty($var))
Post Reply