Uzm Posted October 31, 2007 Share Posted October 31, 2007 Hello, dear PHP/MySQL freaks. For a while ago, i've met a little problem with searching for similar names in database throught php registration system. All right, i've this registration page, which allows user to register on my website and use it everywhere on it, of course. Of course, i'm using MySQL database. The problem itself is that i don't what to have similar names. Let's say there is a nick called "test", and i don't want for users to register "test1". Any suggestions about how i can do this? Quote Link to comment https://forums.phpfreaks.com/topic/75551-checking-for-similar-names/ Share on other sites More sharing options...
pocobueno1388 Posted October 31, 2007 Share Posted October 31, 2007 You can try something like this... <?php //This variable comes from your register form $username = $_POST['username']; $query = "SELECT col FROM users WHERE username LIKE '%$username%'"; $result = mysql_query($query)or die(mysql_error()); if (mysql_num_rows($result) < 1){ //Good, register the username } else { //ERROR: Username is similar to one in the DB } ?> Quote Link to comment https://forums.phpfreaks.com/topic/75551-checking-for-similar-names/#findComment-382207 Share on other sites More sharing options...
netpants Posted October 31, 2007 Share Posted October 31, 2007 How would you do this lets say for example if you didnt want the username, and password to be similar? I have sort of the same prob but its with a search form. Quote Link to comment https://forums.phpfreaks.com/topic/75551-checking-for-similar-names/#findComment-382214 Share on other sites More sharing options...
Uzm Posted October 31, 2007 Author Share Posted October 31, 2007 pocobueno1388, Yes, i've tried that solution. But it will not work if user writes in form "username", "test1". Then, SQL checks if there are similar nicknames for "test1", but there are none. Then it will be OK to do one. As you see, this solution will not work. netpants, Solve this with JavaScript. Well, i did for a while ago! <script type="text/javascript"> <!-- function checkJoin() { if (document.getElementById("username").value == document.getElementById("password").value) { alert ("Login and password cannot be similar to each other!"); return false; } </script> And in form, input: onSubmit="return checkJoin()" Then you'll need to put INPUT ID on forms (username, and password). Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/75551-checking-for-similar-names/#findComment-382219 Share on other sites More sharing options...
pocobueno1388 Posted October 31, 2007 Share Posted October 31, 2007 I don't understand why it won't work, I don't understand what your trying to say. SQL checks if there are similar nicknames for "test1", but there are none. Then it will be OK to do one. Isn't that what you want? Quote Link to comment https://forums.phpfreaks.com/topic/75551-checking-for-similar-names/#findComment-382221 Share on other sites More sharing options...
Uzm Posted October 31, 2007 Author Share Posted October 31, 2007 pocobueno1388, What i want to do is to block users to register similar names. Let's say, i have username "test" in my database. Then, if a user wants to register "test1" - MySQL cheks if there is a similar username (in this case: similar to "test"). IF there is a similar username to "test1" - the script will show an error. Quote Link to comment https://forums.phpfreaks.com/topic/75551-checking-for-similar-names/#findComment-382225 Share on other sites More sharing options...
fenway Posted October 31, 2007 Share Posted October 31, 2007 You have to define "similar"... and doing this is JS is not robust. Quote Link to comment https://forums.phpfreaks.com/topic/75551-checking-for-similar-names/#findComment-382241 Share on other sites More sharing options...
rajivgonsalves Posted October 31, 2007 Share Posted October 31, 2007 well pocobueno1388 has the right approach if your try something advance try the soundex http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_soundex Quote Link to comment https://forums.phpfreaks.com/topic/75551-checking-for-similar-names/#findComment-382252 Share on other sites More sharing options...
fenway Posted November 1, 2007 Share Posted November 1, 2007 well pocobueno1388 has the right approach if your try something advance try the soundex http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_soundex Extremely limited, especially for things that don't always sound like words (e.g. username)... easier to roll-your-own. Quote Link to comment https://forums.phpfreaks.com/topic/75551-checking-for-similar-names/#findComment-382730 Share on other sites More sharing options...
Uzm Posted December 20, 2007 Author Share Posted December 20, 2007 Anyways, i havent found a solution for this problem YET. And URL specified in previous posts didn't help me that much (i'm talking about http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_soundex). Quote Link to comment https://forums.phpfreaks.com/topic/75551-checking-for-similar-names/#findComment-419417 Share on other sites More sharing options...
fenway Posted December 20, 2007 Share Posted December 20, 2007 You have to decide how similar to want simialr to be, then write your own function to do it.... or look at a 3rd party soluion. Quote Link to comment https://forums.phpfreaks.com/topic/75551-checking-for-similar-names/#findComment-419687 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.