looks fine to me. Not sure if you are having problems as you didn't state if anything is going wrong. However it shoudl work, a more elegant way to write the query:
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
//better to enclose strings in quotes ALWAYS - AND SINGLE QUOTES PROCESS FASTER
$result = mysql_query('SELECT * FROM contacts
WHERE first=\''. $_POST['name'].'\'');