Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 5 of 5
Like Tree3Likes
  • 3 Post By mlseim

Thread: Notice: Undefined index: key

  1. #1
    Junior Member Unrecognized's Avatar
    Join Date
    Apr 2016
    Location
    Netherlands
    Posts
    4
    Member #
    53762

    Notice: Undefined index: key

    Hello everyone,

    I'm new to Web Design Forums not sure if you guys expect a introduction first, I'm not sure either if there is a special subforum for this matter.

    Anyways, I've been busy with PHP lately and not very good or familiar with it.
    So I'm mostly trying to teach myself most of it before I'll start a new study.
    I made a registration and login system with a couple features like:
    • Reset password
    • Email validation
    • Change password

    But when I finished and reloaded my website I came across a PHP error and checked it out but couldn't find anything, maybe because I'm not experienced with it either.

    Here is my error:
    HTML Code:
    Notice: Undefined index: key in C:\xampp\htdocs\resetPassword.php on line 9
    Here is my resetPassword.php:
    [PHP] resetPassword.php - Pastebin.com

    You don't have to give a fix, just tell me how I can solve this and maybe tell me how to fix it myself next time so I can learn from it instead of just copy pasting it.

    Kind regards,

    Dion.

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,686
    Member #
    5580
    Liked
    716 times
    It's a "notice", which is not fatal.
    PHP is using an incoming value that you didn't sanitize or validate.
    It's letting you know that.

    You should make sure all incoming variables and values are what they should be.

    This will eliminate the notice:
    PHP Code:
    if(isset($_GET['key'])){
    // do something to make sure it's supposed to
    // be an integer, string, or whatever you need it to be.
    // in this example, do nothing ... just assign it as is.
    $newKey=$_GET['key'];
    }
    $stmt->execute(array(':token' => $newKey)); 
    If you know your key should be an exact number of characters, or specific characters, you would check for that and assign $newKey only if it matches what you expect. That keeps someone from 'injecting' unwanted values or strings.

    That should happen with ANY incoming values external of your script ....
    $_POST
    $_GET
    etc.

    EDIT:
    I would expect you get a similar notice in a place such as line 37.
    If your server generates an 'error log', you can check that for other notices, warnings, and fatals.
    Last edited by mlseim; Apr 04th, 2016 at 05:32 AM.


  4. #3
    Junior Member Unrecognized's Avatar
    Join Date
    Apr 2016
    Location
    Netherlands
    Posts
    4
    Member #
    53762
    Quote Originally Posted by mlseim View Post
    It's a "notice", which is not fatal.
    PHP is using an incoming value that you didn't sanitize or validate.
    It's letting you know that.

    You should make sure all incoming variables and values are what they should be.

    This will eliminate the notice:
    PHP Code:
    if(isset($_GET['key'])){
    // do something to make sure it's supposed to
    // be an integer, string, or whatever you need it to be.
    // in this example, do nothing ... just assign it as is.
    $newKey=$_GET['key'];
    }
    $stmt->execute(array(':token' => $newKey)); 
    If you know your key should be an exact number of characters, or specific characters, you would check for that and assign $newKey only if it matches what you expect. That keeps someone from 'injecting' unwanted values or strings.

    That should happen with ANY incoming values external of your script ....
    $_POST
    $_GET
    etc.

    EDIT:
    I would expect you get a similar notice in a place such as line 37.
    If your server generates an 'error log', you can check that for other notices, warnings, and fatals.
    Aha, thank you for the explenation, learned something new again. Thanks

  5. #4
    Junior Member
    Join Date
    Jul 2016
    Posts
    5
    Member #
    54780
    I came across a PHP error and checked it out but couldn't find anything, maybe because I'm not experienced with it either.,,,,,,,,,,,,
    SMS Marketing software | Professional SMS Marketing| WP SMS Marketing| Nimble Messaging
    Last edited by willions; Jul 29th, 2016 at 04:32 AM.

  6. #5
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,686
    Member #
    5580
    Liked
    716 times
    @Willions .... what was your PHP error message?



Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:07 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com