I think the 2 easiest options are.....
A) Search the DB first for a duplicate entry as was suggested above.
😎 Sometimes the entries may be duplicate on purpose - in this case, CLEAR the variables before you set them. Thus, if the page is refreshed, no data is passed from the submission form and the variables are empty. Just check for an empty variable and return an error.
Like so...
unset($Username);
unset($Password);
$Username = $HTTP_POST_VARS["Username"];
$Password = $HTTP_POST_VARS["Password"];
if (empty($Username) || empty($Password))
{
echo "<H2> You did not enter a Username and/or Password.
";
echo "<H2> Both are required. Please try again. </H2>";