select count(*) from users where username = '$username_to_test'
put the value returned into variable, such as $count
if( $count > 0 )
{
// the username is taken
}
else
{
// the username is not take
}
similarly, if you have a field called 'id' in your table, you could also do 'select id from users where username = '$username_to_test'
if a value is returned, the username is taken