Jump to content

Searching MySQL database


-Felix-

Recommended Posts

When I a user registers a new account, he/she must choose a user name.

Of course, I dont want two users to pick the same username, so what I need to know is how to search the MySQL table to find out if a specific user name has already been picked?

 

For example, a user enters desired username: Bob

So I need to search if there already is a user registered with "Bob"

How do I do this?

 

mysql_query("SEARCH.....") ????

 

 

 

 

 

Link to comment
Share on other sites

$dbh = mysql_connect('mysql_host:3306','username','password');

mysql_select_db('database');

$query = "SELECT * FROM users_table WHERE username='$username'";

$res = mysql_query($query, $dbh);

$rows = mysql_num_rows($res);

 

if ($rows > 0)

{

echo 'Error!';

}

else

{

// continue to add the user

}

 

mysql_close($dbh);

 

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.