if (isset($_POST['action'])) {
switch ($_POST['action']) {
case 'insert':
insert() ;
break;
case 'remove':
remove() ;
break;
}
}
function insert() {
global $dbh, $userob, $id;
$uid = 696 ;
$query = "INSERT INTO ubbt_EXT_GAMES
(FORUM_ID) VALUES (?) ";
$dbh->do_placeholder_query($query, array($uid), __LINE__, __FILE__);
$userob->clear_cached_perms($uid);
print "The insert has been called.";
exit;
}
function remove() {
global $dbh, $userob, $id;
$uid = 696 ;
$query = "DELETE FROM ubbt_EXT_GAMES
WHERE FORUM_ID = $uid ";
print "The remove has been called.";
exit;
}
$body = <<<EOF
<!DOCTYPE html>
<html>
<head>
<title>
How to call PHP function
on the click of a Button ?
</title>
</head>
<body style="text-align:center;">
<h1 style="color:green;"> Humbugs </h1>
<h4> How to call PHP function on the click of a Button ? </h4>
<br>
<br>
<form method="post">
<input type="submit" class="button" name="insert" value="insert" />
<input type="submit" class="button" name="remove" value="remove" />
</form>
<br>
<br>
<div id="foo"></div>
<br>
</body>
</html>
<script>
$(document).ready(function(){
$('.button').click(function(){
var clickBtnValue = $(this).val();
var ajaxurl = 'cache_builders/custom/portal_box_40.php';
var data = {'action': clickBtnValue};
$.post(ajaxurl, data, function (response) {
// Response div goes here.
$('#foo').html(response);
});
return false;
});
});
</script>
EOF;