Forum Moderators: coopster

Message Too Old, No Replies

Matching case insensitive strings

         

dkin

4:35 am on May 18, 2005 (gmt 0)

10+ Year Member



I have a sign up form, I do not want users to be able to use the same names as those that have already been created,my query thus far is this.

$plresult = mysql_query("SELECT * FROM user_char where name LIKE '$charname'", $link) or die ("query 1: " . mysql_error());

But that does not work, if I put a capital in a name already being used I can sign up with it, how can I alter this query for case insensitivity?

dreamcatcher

7:30 am on May 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use a comparison operator instead:

$plresult = mysql_query("SELECT * FROM user_char where NAME = '$charname' LIMIT 1", $link) or die ("query 1: " . mysql_error());

if (mysql_num_rows($plresult)>0)
{
//name taken
}
else
{
//ok
}

dc

dkin

5:51 pm on May 18, 2005 (gmt 0)

10+ Year Member



correct me if I am wrong but that will interpret BOB and Bob as completely different strings will it not?

dreamcatcher

7:16 pm on May 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To be honest I`m not really sure.

Maybe change your original query to:

$plresult = mysql_query("SELECT * FROM user_char where name LIKE '%$charname%'", $link) or die ("query 1: " . mysql_error());

dc

ergophobe

1:24 am on May 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It should be case-insensitive

[dev.mysql.com...] :


The following two statements illustrate that string comparisons are case-insensitive unless one of the operands is a binary string:

mysql> SELECT 'abc' LIKE 'ABC';
-> 1
mysql> SELECT 'abc' LIKE BINARY 'ABC';
-> 0