Script works completely fine - But Error Log gives me "Undefined Variable"

Discussion in 'PHP' started by Guthix121, Dec 13, 2009.

  1. #1
    I have a script in which $count = "5";

    Now at the bottom of my script is: $count = $whosonline;

    This simply transfers the value of $count to $whosonline, which I use in the next part of the script.

    The whole thing works perfectly fine, but my error log gives me:
    [error] PHP Notice: Undefined variable: whosonline in [directory] on line 38

    Not sure why it's doing that. Is it that I'm not supposed to be introducing variables just like that? Would it make a difference if I did $whosonline = $count?

    Thanks.
     
    Guthix121, Dec 13, 2009 IP
  2. javaongsan

    javaongsan Well-Known Member

    Messages:
    1,054
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #2
    set $whosonline=0;
     
    javaongsan, Dec 13, 2009 IP
  3. Guthix121

    Guthix121 Well-Known Member

    Messages:
    1,078
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    105
    #3
    But $whosonline isn't equal to 0 :confused:
     
    Guthix121, Dec 16, 2009 IP
  4. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #4
    Should it not be that $whoisonline = $count and not the other way around as described in your post ?

    $count is already functioning without errors because it has a value, thus its defined, so now you need to apply the value to $whoisonline rather then changing the variable name to $whoisonline

    So at the bottom of your script or wherever else is appropriate, in preparation for the second part of your script:

    $whoisonline = $count;
    PHP:
     
    MyVodaFone, Dec 17, 2009 IP
  5. Guthix121

    Guthix121 Well-Known Member

    Messages:
    1,078
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    105
    #5
    Works, thanks.
     
    Guthix121, Dec 17, 2009 IP