As Torben mentioned, you cannot perform PHP functions in browser events, since the language is server-side, not client-side. However, there are several ways to solve this problem:
1. SERVER-SIDE (PHP)
You cannot call the PHP function in a browser event (for example, click the link), but you can call it the first thing on the page loaded when you click on the hyperlink - let it call next_php ". For this, call the deleteUserMeta() function conditionally, at the very top parts of 'next.php'. Trap - you need to pass some variables to this page so you can check the condition and execute the function. Use GET to pass the variable through a hyperlink as follows:
<a href="next.php?unsubscribe=true&userID=343">Unsubscribe</a>
How you want to pass userId is up to you. In the above example, it is hardcoded, but you can also somehow install it using PHP as follows:
<a href="next.php?unsubscribe=true&userID=<?php echo $userID;?>">Unsubscribe</a>
Now in 'next.php' use the condition to evaluate this variable:
<?php if($_REQUEST['unsubscribe'] == 'true'){ deleteUserMeta($_REQUEST['userID']); } ?>
2. CLIENT PARTY (AJAX)
Another way to perform this operation is to do it on the client side with some AJAX. If you are not familiar with Javascript / jQuery / AJAX, I would probably stick with a different solution, as it is probably easier to implement. If you are using jQuery already, this should not be too complicated. With jQuery, you can bind this function to the actual click event of your hyperlink. Thus, all this operation can happen without refreshing the page:
<a href="#" onclick="ajaxDeleteUserMeta()">Unsubscribe/a>
Now you need two things: 1. The same PHP file βnext.phpβ that was needed for the first solution just contains a call to your function, deleteUserMeta($userId) 2. A javascript function called ajaxDeleteUserMeta() , so create it in its JS as follows: (since it is a named function, it does not need to go inside jQuery(document).ready(function(){}); as most anonymous jQuery functions do).
function ajaxDeleteUserMeta(){ var userID = '';
Long-term, but I hope some of them make little sense.