Trying to make a login page...inputs are username and password.

So i need to search the db to see if the username exisits first then, if so, check the password is ok, thought i could do something like,

PHP Code:
$link mysql_query("select * from tlogin where username = '".$username."'");

if(!
$link){

echo 
"wrong username";

}else{


Can i do that or is there a better way ?