For preventing the page refresh, a cookie will be usefull; To check the empty fields, isset()
<?php
//in the top of the page, BEFORE every output!
if(isset($_COOKIE['givemeaname'])){
setcookie('givemeaname', 'some foo&bar data, maybe a timestamp?', time()+3600);
//now check the mandatory fields and
//do whatever you want with your db
}else{
//do nothing, the page is been refreshed!
}
//do whatever you have to do now!
?>
If you dont like to move your db-about code in the top of the page, in the cookie check you can valorize an boolean var, and then just chet it... choose your path.
Instead of the cookie, you can use a session, if is more convenience for you.. but the behavior should be clear ;)
This solution will save you all the times, becose even if you are hitting the page with a POST form, some browser ask to resend the information again when prompted to refresh the page (and the lazy users usually click 'yes' without reading or understand what it means ;)