문제

I would like to know how to check if login exist in my database. At this moment I am using mysql_num_rows() ,but two hours ago I realised that this is not safe for my website because if I Sign up with nickname: Paul and my friend sign up with nickname: PauL, my website let register these nicknames... I don't know how to check if word is equal to the same word just different letters...

도움이 되었습니까?

해결책

SELECT whatever FROM users WHERE UCASE(username) = 'USERNAMEINUPPERCASE';

Basically, if you use the UCASE() function, you convert (for the purposes of the query) the usernames in the table to uppercase, and then compare to the uppercase version of what you want, making your query case-insensitive.

http://dev.mysql.com/doc/refman/5.0/en/string-functions.html

다른 팁

Assuming that you mean the mix of upper case and lower case. For example, paul,Paul,PAUL,pAUL should treat as single name in the database.

Then, you should use this sql query to check if the name is already existed:

SELECT * FROM table1 WHERE LOWER(table1.nickname) = LOWER('PaUl')

This will convert data in column 'nickname' to lower case and convert 'PaUl' to lower before perform the equality checking.

Before doing the comparison, use the function strtolower() on both variables

You can define that in the SELECT query

SELECT * FROM `table` WHERE LOWER(`Nickname`) = LOWER($nickname)

But depends on your collation *_ci for case insensitive or _cs for case sensitive. If you have *_ci you don't have anything to worry about.

First of all, usernames should be unique and not case-sensitive; set the field Collation for username to utf8_unicode_ci or utf8_general_ci in the database.

then run your current query.

SELECT * FROM users WHERE username = '$_var'
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top