Since the page loads sequentially and if you are working in PHP, you could create a database connection on that page and have it at the top of the page as a php query that connects to the db, and performs the action.
Or you could have it in a separate php file, have a form on your HTML page with this php page as its action and on page load submit the form via either ajax or straight JS on either document.ready if using jQuery or window.onload if using js. Note that simply passing to the other form page will either need a header redirection back or be done with AJAX to not remove the user from the page.
initialPage.html
//HTML stuff
<form id="someForm" action="editUser.php" method="POST">
<input type="hidden" name="logUser" value="login"/>
</form>
//js in initialPage.html
$(document).ready(function(){
$('#someForm').submit();
})
//editUser.php
session_start();
//appropriate database connection validation etc
if(isset($_POST('logUser')){
//php stuff
$q_edituser = "INSERT INTO hk_logs (type, time, who_done) VALUES('Logged In','". time() ."','{$_SESSION['user']['username']}')";
//other PHP stuff
}