Basically...
// Put your connect stuff here.
// Then run a quick query to check to see if it exists.
$qry = ("SELECT * FROM table WHERE username = '".$_POST['username']."'");
$countusername = mysql_num_rows($qry);
// If the count is bigger than 0, echo an error, otherwise continue with the script.
If($countusername > 0){
echo "That username is already in our database. Please go back andd try a different username.";
} else {
// Put your insert stuff here.
}
There are many was to do this, but this should get you started.