This is a function i use when people are registering, it is used to check if the username already exists, im guessing you could quite easily modify it to your needs?
function usernameTaken($username){
global $conn;
if(!get_magic_quotes_gpc()){
$username = addslashes($username);
}
$q = "select username from users where username = '$username'";
$result = mysql_query($q,$conn);
return (mysql_numrows($result) > 0);
}
Note please, $conn is a vraible with my connection information, replace line with your connection details. The field 'username' is from my table 'users', change these two to your own field/table respectively.
You can then just use an if() function on that function, it will return true if the username already exists, or false if otherwise.
Hope that helps