2

I have a table where users enters there username in both lower case(eg: arup) and uppercase(eg: Arup) or both (eg: aRuP).

But my problem is now that if I search database to show member username like %Arup, mysql returns empty result if not founds exactly.

 id    |   username   |   name    |   sex
  1         arUp         Arup Sarma   Male

<?php
$q=strip_tags($_POST['user']); /// eg. Arup
$qry=mysql_fetch_row(mysql_query("SELECT id,name,sex FROM membertable WHERE username='%$q'"));
echo $qry['0']."<br>".$qry['1']."<br>".$qry['2'];
?>
/// Now above sql query will return zero result as there is no username in the form of arUp.

How to make SQL query Case-insensitive ? anyone help please...

Haren Sarma
  • 2,267
  • 6
  • 43
  • 72
  • while not a duplicate, this question provides useful related answers https://stackoverflow.com/questions/16558967/how-to-check-for-uppercase-letters-in-mysql – Kay V Oct 04 '22 at 19:01

3 Answers3

6

I think that this link could help to understand your problem...
Anyway you could solve your problem with this:

SELECT * FROM your_table 
WHERE LOWER(username) LIKE '%arup'
Marco
  • 56,740
  • 14
  • 129
  • 152
2

You can call UPPER on both sides of the comparison:

SELECT id,name,sex FROM membertable WHERE UPPER(username) = UPPER('%$q')

The "right way", according to the official manual, is choosing a case-insensitive collation, which might be faster but is also more complicated.

RavuAlHemio
  • 2,331
  • 19
  • 22
0

based on this: http://dev.mysql.com/doc/refman/5.0/en/case-sensitivity.html

i'd try this:

where username COLLATE latin1_swedish_ci = '%$q'
Ramy
  • 20,541
  • 41
  • 103
  • 153