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
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!

Link to comment
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!

 

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.

Link to comment
Share on other sites

i guess this guy mean is SQL not php

 

try

LOWER()

UPPER()

 

$result = sql_query("SELECT UPPER(m_user) as  x FROM $membtable

WHERE  x='".strtoupper($en['user'])."' ;

 

i guess this is what you mean

 

 

That is exacty what I posted several posts ago.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

 

 

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.