acctman Posted September 6, 2007 Share Posted September 6, 2007 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 More sharing options...
trq Posted September 6, 2007 Share Posted September 6, 2007 Do you meen you want it to find John and JOHN as the same user? Link to comment https://forums.phpfreaks.com/topic/68162-solved-case-sensitive-database-lookup/#findComment-342699 Share on other sites More sharing options...
acctman Posted September 6, 2007 Author Share Posted September 6, 2007 Do you meen you want it to find John and JOHN as the same user? yes, any case variation of John to be the same name Link to comment https://forums.phpfreaks.com/topic/68162-solved-case-sensitive-database-lookup/#findComment-342705 Share on other sites More sharing options...
trq Posted September 6, 2007 Share Posted September 6, 2007 $result = sql_query("SELECT LCASE(m_user) FROM $membtable WHERE m_user='" . strtolower($en['user']) . '"); Link to comment https://forums.phpfreaks.com/topic/68162-solved-case-sensitive-database-lookup/#findComment-342710 Share on other sites More sharing options...
teng84 Posted September 6, 2007 Share Posted September 6, 2007 $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 https://forums.phpfreaks.com/topic/68162-solved-case-sensitive-database-lookup/#findComment-342711 Share on other sites More sharing options...
acctman Posted September 6, 2007 Author Share Posted September 6, 2007 will both examples find joHn, john, JoHN, JOhn, etc as the same? Link to comment https://forums.phpfreaks.com/topic/68162-solved-case-sensitive-database-lookup/#findComment-342715 Share on other sites More sharing options...
corbin Posted September 6, 2007 Share Posted September 6, 2007 Unless I'm mistaken, MySQL is case insensative by default. Link to comment https://forums.phpfreaks.com/topic/68162-solved-case-sensitive-database-lookup/#findComment-342716 Share on other sites More sharing options...
corbin Posted September 6, 2007 Share Posted September 6, 2007 $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 https://forums.phpfreaks.com/topic/68162-solved-case-sensitive-database-lookup/#findComment-342717 Share on other sites More sharing options...
trq Posted September 6, 2007 Share Posted September 6, 2007 Yes I believe MySql is case insensative by default, but the op is using sql_query() so one would assume he may not be using MySql. Link to comment https://forums.phpfreaks.com/topic/68162-solved-case-sensitive-database-lookup/#findComment-342718 Share on other sites More sharing options...
teng84 Posted September 6, 2007 Share Posted September 6, 2007 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 Link to comment https://forums.phpfreaks.com/topic/68162-solved-case-sensitive-database-lookup/#findComment-342719 Share on other sites More sharing options...
trq Posted September 6, 2007 Share Posted September 6, 2007 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 https://forums.phpfreaks.com/topic/68162-solved-case-sensitive-database-lookup/#findComment-342720 Share on other sites More sharing options...
corbin Posted September 6, 2007 Share Posted September 6, 2007 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 https://forums.phpfreaks.com/topic/68162-solved-case-sensitive-database-lookup/#findComment-342721 Share on other sites More sharing options...
trq Posted September 6, 2007 Share Posted September 6, 2007 Well, we can safely assume that whatever db is being used it is not case insensative, otherwise, why post the question? Link to comment https://forums.phpfreaks.com/topic/68162-solved-case-sensitive-database-lookup/#findComment-342722 Share on other sites More sharing options...
acctman Posted September 6, 2007 Author Share Posted September 6, 2007 i'm using Mysql/PHP... i'm editing a current script Link to comment https://forums.phpfreaks.com/topic/68162-solved-case-sensitive-database-lookup/#findComment-342725 Share on other sites More sharing options...
teng84 Posted September 6, 2007 Share Posted September 6, 2007 then no prob with that mysql is case insensitive just like what the other guys is saying Link to comment https://forums.phpfreaks.com/topic/68162-solved-case-sensitive-database-lookup/#findComment-342726 Share on other sites More sharing options...
acctman Posted September 6, 2007 Author Share Posted September 6, 2007 i would have to change the m_user field in the mysql db to TINYTEXT to be case insensitive right... that would back jOhn, JOHN, joHN, JoHN, etc... all be the same as 'john' right? And no special coding would be needed when doing php queries right? Link to comment https://forums.phpfreaks.com/topic/68162-solved-case-sensitive-database-lookup/#findComment-342823 Share on other sites More sharing options...
Barand Posted September 6, 2007 Share Posted September 6, 2007 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 https://forums.phpfreaks.com/topic/68162-solved-case-sensitive-database-lookup/#findComment-342827 Share on other sites More sharing options...
acctman Posted September 6, 2007 Author Share Posted September 6, 2007 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 https://forums.phpfreaks.com/topic/68162-solved-case-sensitive-database-lookup/#findComment-342831 Share on other sites More sharing options...
Barand Posted September 6, 2007 Share Posted September 6, 2007 is m_user a primary key or defined as unique? Link to comment https://forums.phpfreaks.com/topic/68162-solved-case-sensitive-database-lookup/#findComment-342836 Share on other sites More sharing options...
acctman Posted September 6, 2007 Author Share Posted September 6, 2007 is m_user a primary key or defined as unique? not primary or defined as unique Link to comment https://forums.phpfreaks.com/topic/68162-solved-case-sensitive-database-lookup/#findComment-342843 Share on other sites More sharing options...
Barand Posted September 6, 2007 Share Posted September 6, 2007 in which case you can have john, john, john, John as different accounts Link to comment https://forums.phpfreaks.com/topic/68162-solved-case-sensitive-database-lookup/#findComment-342846 Share on other sites More sharing options...
acctman Posted September 6, 2007 Author Share Posted September 6, 2007 so by making 'm_user' index type:UNIQUE, it would make all new entry case insensitive? Link to comment https://forums.phpfreaks.com/topic/68162-solved-case-sensitive-database-lookup/#findComment-342864 Share on other sites More sharing options...
Barand Posted September 6, 2007 Share Posted September 6, 2007 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. Link to comment https://forums.phpfreaks.com/topic/68162-solved-case-sensitive-database-lookup/#findComment-342865 Share on other sites More sharing options...
acctman Posted September 6, 2007 Author Share Posted September 6, 2007 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 https://forums.phpfreaks.com/topic/68162-solved-case-sensitive-database-lookup/#findComment-342876 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.