Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2013
    Posts
    1
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Issues with PHP & mySQL

    Me and a few friends are attempting to creating a social network with a YouTube tutorial. In this specific video, https://www.youtube.com/watch?v=Ooxe6TPt8vM, we are having trouble. When the user puts in the correct credentials, it gives an error message and will not accept those credentials. The PHP debugging says this "Notice: Undefined index: user_login in [--site directory--]/inc/incfiles/header.inc.php on line 6". The mySQL database can be read and can be seen as the login creds are in the system. The user_login index is defined in the index.php file

    Here are the links to our code~
    logout.php: http://pastebin.com/sTkpzwXW
    home.php: http://pastebin.com/PN1FVTft
    header.inc.php: http://pastebin.com/AEdvjyet
    index.php: http://pastebin.com/TpXiGRsA

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    The notice itself is not the problem. That is caused by attempting to read from the $_SESSION superglobal without having the data in it. The next line indicates what you should do; you must always use isset() to verify something exists before attempting to read from it. So the problem itself is elsewhere.

    So what you should see happen is as such. When you hit the index.php page the first time for the session, you should see an error with undefined index (which can be fixed with the isset check). Then, you should login and it should take you back to the index without the notice. That's if its functioning properly.
    Find this in index.php:
    PHP Code:
                     $_SESSION["id"] = $id;
                     
    $_SESSION["user_login"] = $user_login;
                     
    $_SESSION["password_login"] = $password_login
    And add:
    PHP Code:
    print_r($_SESSION); 
    Directly after it. Do you see everything within the sessions specified? If so, then add a print_r($_SESSION); immediately after the call to session_start() in header.inc.php.

    Also, you should change <? to <?php. Short form notation is a feature of the language, and is not guaranteed to be available on every server. <?php will always work. Try searching as well for tutorials built in at least 5.2+ as well (I didn't see this link here, but there's some oldish stuff), things like the mysql library are now obsolete; they are replaced with the mysqli library and PDO is another option.

    Edit:
    Oh yes that reminds me. There is a difference between what you allow during registration and login. One accepts only alphanumeric characters, and the other accepts any characters but removes html from them. You'll need to keep that in mind if you are attempting to use a username or password with non-alphanumeric characters (my name wouldn't work for example; I could sign up, but not log in).
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    williamtech814 (11-15-2013)


  •  

    Tags for this Thread

    Posting Permissions

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