How to make "user name already taken" feature

  • Thread starter Thread starter Anonymous
  • Start date Start date
A

Anonymous

Guest
Anyone know how to search for a database (MySQL) entry and if there is, display a message and if there isn't display another (with PHP)? I'm making a registration form and wanna add the "user name chosen is already taken" thing.
 
Code:
$username = 'Coditor'; // or wherever you get your username from
$query = "SELECT username FROM users WHERE username='" . $username . "'";
$cursor = mysql_query($query);
if (mysql_fetch_row($cursor)) {
   echo 'This username is already taken';
} else {
   echo 'This username is still available';
}

Coditor
 
Back
Top