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:

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:

$_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…

Take a look at this: MySQL :: MySQL 5.5 Reference Manual :: C.5.5.1 Case Sensitivity in String Searches

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.


list($_SESSION['username']) = $check_for_username->fetch_row();

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.

portem, do you check if your query returned something before creating the session variable?

Thank you guys for opening my eyes, actually pretty ‘duh’ on my part. :blush:

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:

	$username = $row['username'];

It now works correctly. :slight_smile: