What would be the cleanest way to run the PHP code below but instead of $_GET, using $_POST instead?
<?php
function run_my_function() {
echo 'I just ran a PHP function!';
}
if (isset($_GET['run'])) {
run_my_function();
}
?>
<html>
<body>
<p>Hello there! <a href="?run">Run a PHP function.</a></p>
</body>
</html>
NO, you cannot send post request from anchor tag. you will have to use <form>
use jquery to do that , check this example
<?php
if (isset($_POST)) {
function run_my_function() {
echo 'I just ran a PHP function!';
}
if (isset($_GET['run'])) {
run_my_function();
}
}
?>
<script>
$(document).ready(function () {
$('#run').click(function () {
$.ajax({
url: '/',
type: 'POST',
success: function(response) {
alert('hiii')
return response;
}
});
});
});
</script>
<body>
<p>Hello there! <a id='run' href="javascript:;">Run a PHP function.</a></p>
</body>