-Need help with- Notice: Undefined variable:

Discussion in 'PHP' started by Hipto, Mar 22, 2010.

  1. #1
    if (isset($_GET['issue']) && !empty($_GET['issue'])) {
        switch($_GET['issue']) {
            case 'badurl':
                $errmsg = '<img src="images/warn.gif" align="absmiddle" border="0" /> The URL you entered could not be found. Please double check your link';
                break;
            
            case 'noaccount':
                $errmsg = '<img src="images/warn.gif" align="absmiddle" border="0" /> No account could be found to complete your download.  Please try again in few minutes.';
                break;
                
            case 'nourl':
                $errmsg = '<img src="images/warn.gif" align="absmiddle" border="0" /> Either you did not enter a valid URL, or we\'re out of Accounts.';
                break;
                
            case 'invalidurl':
                $errmsg = '<img src="images/warn.gif" align="absmiddle" border="0" /> The URL you entered was not a valid URL. Please double check your link';
                break;
            
            case 'exceed':
                $errmsg = '<img src="images/warn.gif" align="absmiddle" border="0" /> You have exceeded the maximum downloads allowed in 24 hours.';
                break;
    
            case 'serprob':
                $errmsg = '<img src="images/warn.gif" align="absmiddle" border="0" /> Seems to be a Server Problem. You may try downloading again.';
                break;
            
            default:
                $errmsg = '';
        }
        $errmsg = '<div id="box"><b>'.$errmsg.'</b></div>';
    }
    PHP:
    <?php echo $errmsg; ?>
    PHP:
    These code are in index.php. And I want to show message with for example index.php?issue=nourl. << This is working fine, but if i simply browse with index.php, I got this error:
    Undefined variable: errmsg in XXXX on line 227
     
    Hipto, Mar 22, 2010 IP
  2. Alex Roxon

    Alex Roxon Active Member

    Messages:
    424
    Likes Received:
    11
    Best Answers:
    7
    Trophy Points:
    80
    #2
    Most webservers won't output the error. Your current error display settings are configured for developers, so you should be fine when uploading.

    Either way, should be a simple case of declaring the variable at the start of your script. i.e. for index.php:

    <?php
    
    $errmsg = '';
    PHP:
    Or you could only output if the variable has been initialized:
    if( isset( $errmsg ) ) echo $errmsg;
    PHP:
     
    Alex Roxon, Mar 22, 2010 IP
  3. waterbomm

    waterbomm Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You can try code below.
    how about it?

    
    $errmsg = '<div id="box"><b>';
    if (isset($_GET['issue']) && !empty($_GET['issue'])) {
        switch($_GET['issue']) {
            case 'badurl':
                $errmsg .= '<img src="images/warn.gif" align="absmiddle" border="0" /> The URL you entered could not be found. Please double check your link';
                break;
           
            case 'noaccount':
                $errmsg .= '<img src="images/warn.gif" align="absmiddle" border="0" /> No account could be found to complete your download.  Please try again in few minutes.';
                break;
               
            case 'nourl':
                $errmsg .= '<img src="images/warn.gif" align="absmiddle" border="0" /> Either you did not enter a valid URL, or we\'re out of Accounts.';
                break;
               
            case 'invalidurl':
                $errmsg .= '<img src="images/warn.gif" align="absmiddle" border="0" /> The URL you entered was not a valid URL. Please double check your link';
                break;
           
            case 'exceed':
                $errmsg .= '<img src="images/warn.gif" align="absmiddle" border="0" /> You have exceeded the maximum downloads allowed in 24 hours.';
                break;
    
            case 'serprob':
                $errmsg .= '<img src="images/warn.gif" align="absmiddle" border="0" /> Seems to be a Server Problem. You may try downloading again.';
                break;
           
            default:
                $errmsg .= '';
        }
        $errmsg = '</b></div>';
    }
    
    PHP:
     
    waterbomm, Mar 22, 2010 IP
  4. Alex Roxon

    Alex Roxon Active Member

    Messages:
    424
    Likes Received:
    11
    Best Answers:
    7
    Trophy Points:
    80
    #4
    Above code will not work. Use my fix.
     
    Alex Roxon, Mar 23, 2010 IP
  5. waterbomm

    waterbomm Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Upz... missing "." in the end of code

    
    $errmsg = '<div id="box"><b>';
    if (isset($_GET['issue']) && !empty($_GET['issue'])) {
        switch($_GET['issue']) {
            case 'badurl':
                $errmsg .= '<img src="images/warn.gif" align="absmiddle" border="0" /> The URL you entered could not be found. Please double check your link';
                break;
           
            case 'noaccount':
                $errmsg .= '<img src="images/warn.gif" align="absmiddle" border="0" /> No account could be found to complete your download.  Please try again in few minutes.';
                break;
               
            case 'nourl':
                $errmsg .= '<img src="images/warn.gif" align="absmiddle" border="0" /> Either you did not enter a valid URL, or we\'re out of Accounts.';
                break;
               
            case 'invalidurl':
                $errmsg .= '<img src="images/warn.gif" align="absmiddle" border="0" /> The URL you entered was not a valid URL. Please double check your link';
                break;
           
            case 'exceed':
                $errmsg .= '<img src="images/warn.gif" align="absmiddle" border="0" /> You have exceeded the maximum downloads allowed in 24 hours.';
                break;
    
            case 'serprob':
                $errmsg .= '<img src="images/warn.gif" align="absmiddle" border="0" /> Seems to be a Server Problem. You may try downloading again.';
                break;
           
            default:
                $errmsg .= '';
        }
    }
    $errmsg .= '</b></div>';
    
    PHP:
     
    waterbomm, Mar 23, 2010 IP