Page 1 of 2

MySQL-output is case-sensitive?

Posted: Fri Aug 07, 2009 8:11 am
by Lureren
Hello!

Atm. im building a new website with a adminpanel and of course a login-system. But when i enter the username it's in case-sensivity, which i dont want. Eg. "Lureren" works because that is how its entered in the database, while "lureren" doesnt work?

How can i change that?

Im out!

Re: MySQL-output is case-sensitive?

Posted: Fri Aug 07, 2009 8:16 am
by Eran
All the character sets ending with a _ci are case insensitive, so use one of those for the username field.

Re: MySQL-output is case-sensitive?

Posted: Fri Aug 07, 2009 8:18 am
by marty pain
Here you are mate
http://us2.php.net/manual/en/function.strtoupper.php

Convert the user name to upper case before saving it to the database, and again when the user enters their user name to login. Hope that helps!

Re: MySQL-output is case-sensitive?

Posted: Fri Aug 07, 2009 8:22 am
by Eran
but then he can't display the username in the original case the user entered it in, which could be confusing / unwanted behavior.

Re: MySQL-output is case-sensitive?

Posted: Fri Aug 07, 2009 8:26 am
by Lureren
So basicly i just change the characterset in the database?

Re: MySQL-output is case-sensitive?

Posted: Fri Aug 07, 2009 8:28 am
by Eran
correct. better backup the table just in case if you have important data in there

Re: MySQL-output is case-sensitive?

Posted: Fri Aug 07, 2009 8:29 am
by Lureren
Ill give it a try. Thank you ;)

Re: MySQL-output is case-sensitive?

Posted: Fri Aug 07, 2009 8:31 am
by marty pain
pytrin wrote:but then he can't display the username in the original case the user entered it in, which could be confusing / unwanted behavior.
True.

If it's not important, then it's an easy fix, but you're right, sorting out the character set is a better solution.

Re: MySQL-output is case-sensitive?

Posted: Fri Aug 07, 2009 8:42 am
by Lureren
Ive now tried som different charactersets, but none of them works.

Any suggestions?

Re: MySQL-output is case-sensitive?

Posted: Fri Aug 07, 2009 8:54 am
by Eran
which ones did you try? you should be using a character set that matches your page encoding, regardless. There shouldn't be that many that match

Also, read the manual - http://dev.mysql.com/doc/refman/5.0/en/ ... ivity.html

Re: MySQL-output is case-sensitive?

Posted: Fri Aug 07, 2009 9:01 am
by Lureren
The webpage is using ISO-8859-1 and in the table ive tried latin1_danish_ci, latin1_swedish_ci, latin1_general_ci, utf8_general_ci and utf8_danish_ci.

Re: MySQL-output is case-sensitive?

Posted: Fri Aug 07, 2009 9:07 am
by Eran
either of the latin ci's should work. What is the query you are running?

Re: MySQL-output is case-sensitive?

Posted: Fri Aug 07, 2009 9:36 am
by Lureren

Code: Select all

$postUsername = $_POST["username"];
$sql = mysql_query("SELECT username,password FROM user WHERE username = '$postUsername'");
$sqlArray = mysql_fetch_array($sql);
 
if($sqlArray["username"] == $_POST["username"] AND $sqlArray["password"] == md5($_POST["password"]))
{
    $_SESSION["logon"] = $postUsername;
}
else
{
    echo "<p>Wrong login!</p>";
}

Re: MySQL-output is case-sensitive?

Posted: Fri Aug 07, 2009 9:47 am
by Eran
What you are doing is kind of redundant though I don't think it's related to you error. Since you are retrieving a row by its username, you only have to check that the results are not empty, not compare again the username. You should check that your query produces no errors and that any rows has been retrieved.

Re: MySQL-output is case-sensitive?

Posted: Fri Aug 07, 2009 10:01 am
by Lureren
I removed the "== $_POST["username"]" and now it works!

Thanks alot!