SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    May 2010
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Retrieve username as it is stored (case sensitivity)

    hi, I have a php script that I use to retrieve a username from mysql like so:

    PHP Code:
    if (isset($_POST['username'])) {
    $username mysqli_real_escape_string($link$_POST['username']);
    $check_for_username mysqli_query($link"SELECT username FROM members WHERE username = '$username'"); 
    and then I create part of my session like this:

    PHP Code:
    $_SESSION['username'] = $username
    My question is, how can I make it so the result from the mysql query retrieves the username exactly as it is stored in the db?

    Currently I can post whatever case format I want (UsErnamE or UsERNAME) and the username will always display in future echos however I typed it in the form.

    I want it to only display as it is stored in the DB.

    If this is not a MySQL question I apologize, but it seems like it would be to me..

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)

  3. #3
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    Which.. actually has nothing to do with what he's asking.

    Your problem is that you're storing the input from the user, instead of the return from the database.
    PHP Code:
    list($_SESSION['username']) = $check_for_username->fetch_row(); 

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by StarLion View Post
    Which.. actually has nothing to do with what he's asking.
    Reading the OP again, you might be right.
    I thought he meant he always got a value returned, even if he shouldn't (like: the value in the database is 'John', I type 'john' and it still returns a value), because the select is case insensitive and he didn't want that.

  5. #5
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    portem, do you check if your query returned something before creating the session variable?

  6. #6
    SitePoint Zealot
    Join Date
    May 2010
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you guys for opening my eyes, actually pretty 'duh' on my part.

    I've been storing the original user input as the session instead of the result from the db query.

    Further down in the code I was actually already getting the userid and storing it as a row, just edited that code to also get the username and added:

    PHP Code:
        $username $row['username']; 
    It now works correctly.


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
  •