0

I have table which contain [Username, Email] and I'm checking them for non repeating any of them,

but It's case-sensitive , so if there is user that's Username is "SelvsterTP", if other user typed it, he won't be able to register, but if he type "selvstertp" for example, no errors face him! ,

I think of making extra column called 'UsernameCheck' and upload to it Username 'lowercase' , then check on that column (same with Email) ,

but it seems to me not the best code for that situation, so any ideas or suggestions?

Original code

$CheckusernameRow = 
RowCountDB("Id","users","Username",$Username); //function   
to get rows

My Idea

 $CheckusernameRow = 
 RowCountDB("Id","users","UsernameCheck",strtolower($Username));
Mazen Amir
  • 81
  • 7
  • try using `binary` in front of the column value which to be searched. like `select * from my_table where Username = binary 'selvstertp'` – James Oct 06 '19 at 04:53
  • The default collation (in English, at least) is case-insensitive, so perhaps there's a case-insensitive collation for your preferred charset too. – Strawberry Oct 06 '19 at 08:13
  • Possible duplicate of [How can I make SQL case sensitive string comparison on MySQL?](https://stackoverflow.com/questions/5629111/how-can-i-make-sql-case-sensitive-string-comparison-on-mysql) – Mike Doe Oct 07 '19 at 11:21

1 Answers1

-1

Did you try the LOWER() selector?

$lowerUsername = strtolower($Username);
$query = "SELECT id FROM users WHERE LOWER(Username) LIKE '$lowerUsername'";
JBA
  • 2,889
  • 1
  • 21
  • 38