phillystyle123
asked on
Default php variable
I'm calling an include at the very top of my code:
includes/page_top.php
i've got this line of code in includes/page_top.php:
<?php if ($crumb2=="wirtzer") echo "Active";?>
now, in the code of the page that is calling includes/page_top.php, i'm defining the crumb2 variable: i.e.:
<?php $crumb2="wirtzer";?>
my issue is that i'm getting server errors (not on the php page but in the log files) like this one:
[Sat Feb 05 10:03:06 2011] [client 76.168.200.119] PHP Notice: Undefined variable: crumb2 in /home/derm/includes/submen u-forms.ph p on line 3
i'm guessing this is because includes/page_top.php loads before the rest of the code containing the actual crumb2 variable definition. can i define a default crumb2 variable in includes/page_top.php? so i don't keep getting these errors?
includes/page_top.php
i've got this line of code in includes/page_top.php:
<?php if ($crumb2=="wirtzer") echo "Active";?>
now, in the code of the page that is calling includes/page_top.php, i'm defining the crumb2 variable: i.e.:
<?php $crumb2="wirtzer";?>
my issue is that i'm getting server errors (not on the php page but in the log files) like this one:
[Sat Feb 05 10:03:06 2011] [client 76.168.200.119] PHP Notice: Undefined variable: crumb2 in /home/derm/includes/submen
i'm guessing this is because includes/page_top.php loads before the rest of the code containing the actual crumb2 variable definition. can i define a default crumb2 variable in includes/page_top.php? so i don't keep getting these errors?
The definition needs to come before the 'include' or at least before the 'if'. You can define and re-define it wherever you want. It just has to be defined when you try to use it like in the 'if' statement.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank you!