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
https://forums.phpfreaks.com/topic/111043-check-for-duplicate-entries/
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.

Archived

This topic is now archived and is closed to further replies.

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