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
https://forums.phpfreaks.com/topic/2633-searching-mysql-database/
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
https://forums.phpfreaks.com/topic/2633-searching-mysql-database/#findComment-8759
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.