Jump to content

[SOLVED] case sensitive database lookup


acctman

Recommended Posts

my script uses this code to check if a user name exist, how would I make it case sensitive, so John and JOHN will be check as well as any variations?

 

//username exists?
$result = sql_query("SELECT `m_user` FROM $membtable WHERE m_user='{$en['user']}'");
        if (sql_num_rows($result) > 0) $err .= _reg_member_exists.'<br>';

Link to comment
https://forums.phpfreaks.com/topic/68162-solved-case-sensitive-database-lookup/
Share on other sites

$result = sql_query("SELECT `m_user` FROM $membtable 
WHERE m_user='".strtolower($en['user'])."' 
or  m_user='".strtoupper($en['user'])."' 
or m_user='{$en['user'])}'  ");

is that what you mean

 

i notice that this is almost the same as thorpe have but in case!

$result = sql_query("SELECT `m_user` FROM $membtable 
WHERE m_user='".strtolower($en['user'])."' 
or  m_user='".strtoupper($en['user'])."' 
or m_user='{$en['user'])}'  ");

is that what you mean

 

i notice that this is almost the same as thorpe have but in case!

 

Assuming MySQL WHERE clauses are case sensative, this won't work....

 

Let's assume 'Corbin' is stored in the db and 'cOrbin' is $en['user'].

 

strtolower('cOrbin') -> 'corbin'

strtoupper('cOrbin') -> 'CORBIN'

 

corbin, CORBIN, and cOrbin all do not match Corbin.

Ahhh.... I read that as mysql_query.... So used to seeing mysql around these forums, I just see it that way now ;p.

 

I think MSSQL is case insensative as well, and I would assume other database systems are although all I've ever used is MySQL MSSQL and a little bit of Access.

Case insensitivity will depend on the particular collation being used

 

Notice that there is a convention for collation names: They start with the name of the character set they are associated with, they usually include a language name, and they end with _ci (case insensitive), _cs (case sensitive), or _bin (binary).

Case insensitivity will depend on the particular collation being used

 

Notice that there is a convention for collation names: They start with the name of the character set they are associated with, they usually include a language name, and they end with _ci (case insensitive), _cs (case sensitive), or _bin (binary).

 

m_user is set to latin1_swedish_ci but both user John and john can be two separate accounts, why is this?

 

 

Then if you have "john" in the column it won't let you add "John" or "jOhn" etc  because they will be treated as same value.

 

thanks exactly what i want =) one more question will i lose any performance by switching from Index to Unique, i'm editting an existing script and I don't understand why the create would not make the username field unique. doesn't make any since for it not to be.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.