On this site, we do not normally open attachments. In order to post code, use the <> button located in the toolbar.
As for your issue, the PHP script will be read by the server when loading the webpage.
It is currently doing what you have directed it to do (and has proven that it functions adequately).
If you want to change your instructions to not run unless the submit button is clicked, then you have created a new CONDITION that needs to be added to the code.
There are several ways to handle this:
//let's say this is your button
<input type="submit" name="my_submit" value="runPHP">
//Assuming the button is inside a <form method="POST"> tag, you now have several alternatives or combinations to use as conditions
<?php if(isset($_POST['my_submit'])){
//code to run if the CONDITION is met hours here
} else {
//what to do if condition is NOT met
echo "Sorry, the button was not clicked";
} //end the condition
//OR do this if you want to meet a greater condition
if(isset($_POST['my_submit']) && $_POST['my_submit'] == "runPHP"){
//code to run if ALL the CONDITIONs are met
} else {
//what to do if conditionS are NOT met
echo "Sorry, the button was not clicked";
} //end the conditions statement
?>
Hope this helps.
You can research ISSET and see other examples online.