Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Feb 2007
    Location
    Albany, Oregon
    Posts
    66
    Thanks
    3
    Thanked 0 Times in 0 Posts

    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'

  • #2
    New Coder
    Join Date
    Feb 2007
    Location
    Albany, Oregon
    Posts
    66
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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.

  • #3
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    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..

  • #4
    New Coder
    Join Date
    Feb 2007
    Location
    Albany, Oregon
    Posts
    66
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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 01:09 AM.

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


  • Users who have thanked Fumigator for this post:

    zach4618 (10-09-2007)

  • #6
    New Coder
    Join Date
    Feb 2007
    Location
    Albany, Oregon
    Posts
    66
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Excellent. Thanks for your help.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •