MySQL Query in PHP - Checking duplicates?

  • Thread starter Thread starter Spyker73
  • Start date Start date
S

Spyker73

Guest
I have something in my website where you pick a name, but I need it to check if the name isn't taken, so how would I use a MySQL query to check what the user typed in. Something like ...

$namecheck = *MySQL query here*

if($namecheck = 0)
*make account*
else
*give error*

Thats basically how my code is
 
Assuming the table where you store the name is users, containing a field 'name' where you store the name, and a field 'id' that contained the record id:

SELECT id FROM users WHERE name=$name;

If a record is found, the name was already in use.
 
Assuming the table where you store the name is users, containing a field 'name' where you store the name, and a field 'id' that contained the record id:

SELECT id FROM users WHERE name=$name;

If a record is found, the name was already in use.
 
Back
Top