Jump to content

Username Check


master82

Recommended Posts

I've created a registration form for my site and started the process of validating the input (check for blanks, length, passwords match etc) but I've come across a problem when it comes to checking the database to see if the requested username is already in use.

I've already included the connection info, from what I remember I have to do an IF(... SELECT and LIMIT or something like that.

Could anyone show me how to do this?
Link to comment
https://forums.phpfreaks.com/topic/11803-username-check/
Share on other sites

You'll want to use Buyocats query and the code will be like this:
[code]//connect to database

$sql = "SELECT user_id FROM user_table WHERE username = '$username' LIMIT 1";
$result = mysql_query($sql);

if(myql_num_rows($result) == 1)
{
    echo "Username in use";
}
else
{
    //continue to register user
}[/code]

Also you might want to set the username field to be UNIQUE too.
Link to comment
https://forums.phpfreaks.com/topic/11803-username-check/#findComment-44736
Share on other sites

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.