I'm a newbie so please bear with me....

I am trying to get my code to check the “username” field and print an error message letting the user know that they left a field blank. Now before all I had was the below code of which it worked in part, in the sense that the below code was executed when the submit button was clicked on and when the page was refreshed.

PHP Code:
  if (isset($_POST['username'])) {
                                        
                               
emptyField();
                                    
                                         }                           
                                             
                          
                                 function 
emptyField()
                                    {
                                      
$var1 "*Field missing entry...";
                                     echo 
$var1;
                                    } 
To fix this I the added the below code, which now meant that the code only worked if the user clicked on the submit button and didn’t work if the page is refreshed. However I’ve also noticed that even when there is text in the “username” field and say the user got there password wrong (not proceeding to the next page), it simply cleared all fields and printed “*Field missing entry...*” Why is this and how do I sort this out…?

PHP Code:
 <?php     
                          
                          
                            
if(isset($_POST['submit']))
                                {
                                    
fieldChecker();
                                }        
                     
                   
                              function 
fieldChecker(){ 
                                  
                                    
// if the field is empty...
                                    
if (isset($_POST['username'])) {
                                        
                                        
emptyField();
                                    
                                         }                        
                                  
                              }                  
                          
                                 function 
emptyField()
                                    {
                                      
$var1 "*Field missing entry...";
                                     echo 
$var1;
                                    }
                          
?>