Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-08-2007, 10:10 PM   PM User | #1
zach4618
New Coder

 
Join Date: Feb 2007
Location: Albany, Oregon
Posts: 66
Thanks: 3
Thanked 0 Times in 0 Posts
zach4618 is an unknown quantity at this point
Error in processing - Undefined Variable

I am having a problem with some php not evaluating the way I would like. On a page that is included on many different pages, I have the following code:

PHP Code:
<a href="http://www.albany.k12.or.us/wahs/teacherpages/welshstuart/class1/calendar/<?php if ($addLevel) {include("../../../currentmonth.php");} else {include("../../currentmonth.php");} ?>.php">Calendar</a>
And on the pages that I have the above code included, addLevel is either set to 1 or not defined at all. For a while this system worked great. Just this past weekend however some work was done on the server that I use and now I get the following error message: "Warning: undefined variable $addLevel..."

Anyone see what I am doing wrong? Here is a URL where it is being used:

http://albany.k12.or.us/wahs/teacher.../bulletins.php

Click on one of the classes and then on 'Calendar'
zach4618 is offline   Reply With Quote
Old 10-08-2007, 10:32 PM   PM User | #2
zach4618
New Coder

 
Join Date: Feb 2007
Location: Albany, Oregon
Posts: 66
Thanks: 3
Thanked 0 Times in 0 Posts
zach4618 is an unknown quantity at this point
I have figured out that if I define addLevel on all pages, but set it to 0 where I do not want the extra level, then this fixes my problem. However, this code is used on quite a few pages and it would not be as practical to define the variable on every page. If someone knows of an easier fix that would be greatly appreciated.
zach4618 is offline   Reply With Quote
Old 10-08-2007, 10:35 PM   PM User | #3
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
That code seems to be missing on that page. You're getting the error because the variable isn't set before you attempt to use it. You should either pre-define it at the top of your page or use "@" to suppress the error. What exactly are you trying to do with that code? It seems like it would either produce an error or at least not the output you intend, to me..
Inigoesdr is offline   Reply With Quote
Old 10-09-2007, 12:05 AM   PM User | #4
zach4618
New Coder

 
Join Date: Feb 2007
Location: Albany, Oregon
Posts: 66
Thanks: 3
Thanked 0 Times in 0 Posts
zach4618 is an unknown quantity at this point
The code is used for teacher pages that I have created at my high school. In the navigation for their class, I want the month that is loaded when someone visits their calendar to be controlled dynamically. Thus I created a file outside their folders called currentmonth.php. At the end of the month, we can change this file to whatever the next month is and the month loaded will be changed for all teachers.

I came across a problem though when I was implementing this. The location of the currentmonth file is different on their calendar pages from the rest of their pages since all the files for the month are inside a 'calendar' folder. To address this I created a variable, addLevel, which is only defined on the calendar pages. In the navigation file, which is included on all of the pages for that class, the currentmonth file is included from three levels up only if addLevel exists. Otherwise, it is included from two levels up. This worked great until this weekend when some work was done on the server. Im not sure exactly what was done but the above described solution no longer works.

This may help you visualize the hierarchy:

- Main directory

-- teacherpages
currentmonth.php

--- teachername

---- class1
navigation.php

----- calendar
october.php

Last edited by zach4618; 10-09-2007 at 12:09 AM..
zach4618 is offline   Reply With Quote
Old 10-09-2007, 12:51 AM   PM User | #5
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
Change your "if" statement to check to see if the variable is set before you use it.
PHP Code:
if (isset($addLevel) && $addLevel) {
    ...

__________________
Fumigator is offline   Reply With Quote
Users who have thanked Fumigator for this post:
zach4618 (10-09-2007)
Old 10-09-2007, 01:26 AM   PM User | #6
zach4618
New Coder

 
Join Date: Feb 2007
Location: Albany, Oregon
Posts: 66
Thanks: 3
Thanked 0 Times in 0 Posts
zach4618 is an unknown quantity at this point
Excellent. Thanks for your help.
zach4618 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:28 AM.


Advertisement
Log in to turn off these ads.