Jump to content

Undefined Variable


iwato

Recommended Posts

GREETING:  Happy New Year, W3Schools!  I am looking forward to another year of online progress.  Hopefully many of the problems that I have been experiencing for the last year and a half will disappear with the addition of a brand new iMac that can handle the latest PHP and MySql software.  This said,  I remain the advanced novice that I am and very much hope that you will continue to stand by my side.

BACKGROUND:  Please find below a set of code that permits one new set of functionality, but destroys another.  The related error messages are provided beneath the code.

if (isset($_GET['refer_type']) && filter_var($_GET['refer_type'], FILTER_VALIDATE_INT)) {
$refer_type = $_GET['refer_type'];
} else {
    $refer_type = 0;
}
if (isset($_GET['panel_type']) && filter_var($_GET['panel_type'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH)) {
    $panel_type = $_GET['panel_type'];
    if (isset($_GET['lang_type']) && filter_var($_GET['lang_type'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH)) {
        $lang_type = $_GET['lang_type'];
    }
} else {
    $panel_type = 0;
}

ERROR MESSAGES:

[05-Jan-2020 04:10:40 UTC] PHP Notice:  Undefined variable: lang_type in /home/thege0/public_html/grammarcaptive.com/devcptv18rs/overview.html on line 99

QUESTION:  Can you see anything in the code line

if (isset($_GET['lang_type']) && filter_var($_GET['lang_type'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH)) {
    $lang_type = $_GET['lang_type'];
}

or elsewhere that could be triggering the error.  The code line just given is new and is clearly the initial, but maybe not the final source of the problem.

By the way, when the code was first introduced, it did not appear to create a problem.  Only several days later did the problem appear.

Roddy

 

Link to comment
Share on other sites

The $lang_type variable is only being created on specific conditions, if these conditions are not met then you will get a warning. You should initialize $lang_type with a default value outside of all of the if statements.

  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...