Notice: Undefined index: rand in .....

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • complearn
    New Member
    • Jan 2009
    • 2

    #1

    Notice: Undefined index: rand in .....

    Do you know why I got these errors for status_bar.php in some webhost, but work perfectly on other webhost?

    Notice: Undefined index: re in /usr/home/daniel/domains/thehornyguy.com/public_html/criminalonline/status_bar.php on line 18

    Notice: Undefined index: rand in /usr/home/daniel/domains/thehornyguy.com/public_html/criminalonline/status_bar.php on line 18
    Whats wrong? here are the codes from line 18, our webhost is running php5.


    [code=php]
    $dmg = ($_GET['re'] == 0 || $_GET['re'] == '22') ? $_GET['rand'] : $_GET['diff']+$_GET['rand'];[/code]
    Last edited by Atli; Jan 5 '09, 09:09 PM. Reason: Replaced all the [b] tags with the appropriate [quote] and [code] tags.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    it looks like neither "re" nor "rand" were defined in the URL, that's why it is always a good idea to check for their existance first:
    Code:
    // expand for all required vars
    if (isset($_GET['re'], $_GET['rand'])) 
    {
        // code coming here
    }

    Comment

    • complearn
      New Member
      • Jan 2009
      • 2

      #3
      what is " // code coming here" please? The full line is there, and I dont know php at all.. please show me the exact line to put back to the file.....

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        the meaning of
        Code:
         // code coming here
        is as follows:
        I don't have a clue*, what code you use on these values, thus replace "// code coming here" with your actual code.

        (btw. // indicates a one line comment)

        * it might be more than line 18.....

        alternatively, you may abort the function if the requirement is not met:
        Code:
        if (!isset($_GET['re'], $_GET['rand']))
        {
            // any default actions
            return false;
        }

        Comment

        • RedSon
          Recognized Expert Expert
          • Jan 2007
          • 4980

          #5
          If you don't know PHP why are you trying to program in it? Don't you think you would be better served by looking over a few tutorials first and trying to learn the language before you try something more advanced?

          Comment

          Working...