Just thought of answering in a better way. We can do it in multiple ways. Let's say if you want to use a Bootstrap button (very common ask). What you can do is execute using three ways:
- Redirection
- AJAX Calls
- Forms
Using Redirection:
<button class="btn btn-primary" onclick="location.href='query.php?run=true';">Run SQL</button>
And then in PHP, you can do:
<?php
// query.php
if ($_GET["run"] == "true") {
$sql = "INSERT INTO contacts_requirements_tbl (employeeid, DocumentName, ExpirationTime,type, exempt) SELECT $id, Docname, ExpirationTime, type, exempt FROM contacts_requirements_tpl ";
mysqli_query($connection_object, $sql);
}
?>
Without a redirection using AJAX calls, you can use this way:
<button class="btn btn-primary" onclick="fetch('query.php?run=true');">Run SQL</button>
Or using a Form:
<form action="query.php?run=true">
<button class="btn btn-primary" type="submit">Run SQL</button>
</form>