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"<form action='edit.php' name='add' method='post'>\n";
echo"<input type=hidden name='tablename' value='$tablename' />\n";
echo"<input type=hidden name='dbname' value='$dbname' />\n";
echo"<table>";
echo"<tr><td colspan=2><center><b>NEW POSITION</b></center><br></td></td>";
echo"<tr><td class=td>Position Title:</td>";
echo"<td class=td><input type=\"text\" name='array[1]' size=\"32\"></td>";
echo"<tr><td class=td>Position Description:</td>";
echo"<td class=td><textarea rows=\"6\" name='array[2]' cols=\"34\"></textarea></td>";
echo"<tr><td colspan=\"2\">";
echo"<button title='New Position' class=buttons type=submit name='addrec'/> Create New </button>\n";
echo"<button onclick=\"history.back();\">Cancel</button></td>";
echo"</table></form>";
$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"<form action='edit.php' name='add' method='post'>\n";
echo"<input type=hidden name='tablename' value='$tablename' />\n";
echo"<input type=hidden name='dbname' value='$dbname' />\n";
echo"<table>";
echo"<tr><td colspan=2><center><b>NEW POSITION</b></center><br></td></td>";
echo"<tr><td class=td>Position Title:</td>";
echo"<td class=td><input type=\"text\" name='array[1]' size=\"32\"></td>";
echo"<tr><td class=td>Position Description:</td>";
echo"<td class=td><textarea rows=\"6\" name='array[2]' cols=\"34\"></textarea></td>";
echo"<tr><td colspan=\"2\">";
echo"<button title='New Position' class=buttons type=submit name='addrec'/> Create New </button>\n";
echo"<button onclick=\"history.back();\">Cancel</button></td>";
echo"</table></form>";