I think you need to do some reading about the diff between client side (javascript) and serverside (php, asp, java) processing.
When you submit a form to php the whole form goes and you will be left with a blank screen if you don't output something.
You have choices, basically output the whole form again with a error message in the html or at the very end have
if (isset($errormsg))
echo "<script language='javascript'>\n alert('$errormsg');\n </script>";