SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jun 2012
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Code fails to obtain "id" from table

    http://pastebin.com/TnUyKZRD
    The table, users, contains the columns "id" (an auto increment value), username, and password.
    username is successfully identified and the user can log in fine, but their "id" is not stored as a session variable like username is, why is this?

  2. #2
    SitePoint Wizard frank1's Avatar
    Join Date
    Oct 2005
    Posts
    1,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by MXIIA View Post
    http://pastebin.com/TnUyKZRD
    The table, users, contains the columns "id" (an auto increment value), username, and password.
    username is successfully identified and the user can log in fine, but their "id" is not stored as a session variable like username is, why is this?
    It is not doing so becuase this line
    $_SESSION['uid']= mysql_query($getuid) or die(mysql_error());

    the function mysql_query returns a resource on success, or FALSE on error not the value

    This should do the trick
    if($login = mysql_fetch_assoc($checkUserQueryResults)){
    $_SESSION[id] = $login[id];
    $_SESSION['username'] = $login['username'];
    $confirm = "Thank you, you are now logged in as $userLogin. <br />You may now continue to the <a href=\"index.php\">index</a>";
    //rather user header function
    }

    Just as it was.I think this login process can be made better.
    But it will work any way.

    Thanks

  3. #3
    SitePoint Member
    Join Date
    Jun 2012
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you!!

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,097
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Off Topic:


    PHP Code:
    foreach($_GET as $key => $value){
    $
    $key $value;

    Please oh please don't do this. There's a reason register_globals was removed from PHP as 5.4.0, because it's super insecure. Don't emulate or fake it instead, just don't use it; use $_GET (or your own wrapper around $_GET) instead.
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


Bookmarks

Posting Permissions

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