Jump to content

Check for duplicate entries


Imad

Recommended Posts

Hi Guys, I need some help with searching for duplicate MySQL row entries. To be more specific, I have a table called users. I want to check to see if a username like the one someone wants to register as, is available or not; if so, I return an error. I did try searching in Google first but I couldn't find it.

Thanks in advanced,

Imad.

Link to comment
Share on other sites

Do like

$con=mysql_connect("host","user","pass");
mysql_select_db("db",$con);

$one=mysql_query("SELECT * FROM users WHERE username='".$_POST["username"]."'");
$two=mysql_num_rows($one);

if ($two!==0) {
  echo("Name taken.");
}
else {
  echo("Name avaliable.");
}

 

Assuming your form with the username is named "username" and its POST.

Link to comment
Share on other sites

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.