Jump to content

Recommended Posts

Hello, dear PHP/MySQL freaks. ;D

 

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?

Link to comment
https://forums.phpfreaks.com/topic/75551-checking-for-similar-names/
Share on other sites

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
}

?>

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! ;D

 

<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.

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.

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.

  • 1 month later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.