PHP - Undefined Index Error Message
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 3 of 3

Thread: PHP - Undefined Index Error Message

  1. #1
    Join Date
    Feb 2007

    PHP - Undefined Index Error Message


    Any assistance on this would be greatly appreciated. It seems I am receiving a 'Undefined Index:" error message with a few of the variables I am trying to define, at least I think I have defined them. Please see code below and messages I am receving - thanks in advance. What have I done wrong???


    <h1> Skyward Aviation</h1>
    <h2>Mileage Credit Updated!</h2>
    <p><a href='<?php echo "FrequentFlyerClub.php?" . SID
    ?>'>Frequent Flyer Club Home Page</a></p>

    $TravelDate = $_GET['year'] . "-" . $_GET['month']
    . "-" . $_GET['date'];
    $Mileage = $_GET['mileage'];

    $DBConnect = mysqli_connect("localhost", "mmacdonald-dow", "web9631")
    Or die("<p>Unable to connect to the database server.</p>" . "<p>Error code " . mysqli_connect_errno()
    . ": " . mysqli_connect_error()) . "</p>";$DBName = "skyward_aviation";
    @mysqli_select_db($DBConnect, $DBName)
    Or die("<p>Unable to select the database.</p>"
    . "<p>Error code " . mysqli_errno($DBConnect)
    . ": " . mysqli_error($DBConnect)). "</p>";

    $TableName = "mileage";
    $SQLstring = "SELECT * FROM $TableName";
    $QueryResult = @mysqli_query($DBConnect, $SQLstring);

    $SQLstring = "INSERT INTO $TableName VALUES(NULL,
    '{$_SESSION['flyerID']}', '$TravelDate', '$Mileage')";
    $QueryResult = @mysqli_query($DBConnect, $SQLstring)
    Or die("<p>Unable to execute the query.</p>"
    . "<p>Error code " . mysqli_errno($DBConnect)
    . ": " . mysqli_error($DBConnect)) . "</p>";mysqli_close($DBConnect);


    Messages -

    Notice: Undefined index: year in c:\Inetpub\wwwroot\

    Notice: Undefined index: month in c:\Inetpub\wwwroot

    Notice: Undefined index: date in

    Notice: Undefined index: mileage in c:\Inetpub\

  2. #2
    Join Date
    Aug 2002

    Talking Re: PHP - Undefined Index Error Message

    Sometimes GET params aren't defined (arent present in URL). For example, in your code:
    PHP Code:
     $Mileage $_GET['mileage']; 
    $_GET['mileage'] isn't defined in your URL probably.

    Try using @ before $_GET[''] variables. Like this:
    PHP Code:
     $Mileage = @$_GET['mileage']; 
    PHP isn't complaining on the $Mileage variable, but on $_GET['mileage'].

    I hope it helps.
    All consequences are eternal in some way.

  3. #3
    Join Date
    Dec 2004

    Re: PHP - Undefined Index Error Message

    Undefined index just means your trying to get something from a position in the array that doesn't exist; they are case sensitive. To get it to work I'd try checking all of the name attributes in your form and check that they match the $_GET array positions you trying to get.

Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)