Display error message when user tries to add duplicate record into MySQL


I am letting users add some information into MySQL database via forms. I have set one of the fields in the database as"unique" to prevent duplicate records. What I want to do is to display message to the user when he/she tries to add the same record twice(i.e submit ethe same form with the same info twice. Usuallu happens when user refreshes the browser). Below is the form that I use to submit info to database. I know that I have to do some checking before all this info is actually inserted into database, but I can't figure how. I tried to do the following without sucsess, can anybody help

$check = "SELECT COUNT(pos_title) FROM $tablename WHERE pos_title='$_POST[array]')";
$check_result = mysql_query($check);

if(mysql_num_rows($check_result)>0)
{
die("YOU have submited it already");
}

echo"\n";
echo"\n";
echo"\n";
echo"";
echo"NEW POSITION
";
echo"Position Title:";
echo"";
echo"Position Description:";
echo"";
echo"";
echo" Create New \n";
echo"Cancel";
echo"";
Posted On: Wednesday 24th of October 2012 12:32:47 AM Total Views:  280
View Complete with Replies

RELATED TOPICS OF PHP PROGRAMMING LANGUAGE