If I understand you correctly then you should be able to put something like this at the top of the PHP script:
if (isset($_POST['doLogin'])){
}
include all the code you only want run after form submission within the if clause. This should check whether the login button has been pressed