Your button is HTML and your function is PHP. They look like together because they are in the same file, but they are not together. PHP exists only on the server. HTML only works on the client (browser). When you see the button on your browser, the PHP is gone, you only have HTML.
To make a HTML button to call a PHP function, you will have to move your function to a PHP file, then make your button to call it with Ajax. Example:
bb1.html : contains button that uses Ajax to call PHP function.
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type = "text/javascript">
function myAjax () {
$.ajax( { type : 'POST',
data : { },
url : 'bb2.php', // <=== CALL THE PHP FUNCTION HERE.
success: function ( data ) {
alert( data ); // <=== VALUE RETURNED FROM FUNCTION.
},
error: function ( xhr ) {
alert( "error" );
}
});
}
</script>
</head>
<body>
<button onclick="myAjax()">Click here</button> <!-- BUTTON CALL PHP FUNCTION -->
</body>
</html>
bb2.php : contains function that returns "hello".
<?php
function bb()
{
echo "hello"; // VALUE RETURNED.
}
bb();
?>
Create two text files with the given names, copy-paste this codes, open your browser and run "localhost/bb1.html".
This is how a button calls a PHP function : Ajax does all the magic.