user is on a page where he has to confirm sign-out of an activity. When clicking on OK the entry of his signup should be deleted in the database and after that he should be redirected. here is the code of the button-handler:
$("#OK").click(function()
{
unsubscribeMember();
window.location.href="signup-for-event.php?memId=" + <?php echo $_SESSION['memberId'] ?>;
});
here is the code of the function unsubscribeMember();
function unsubscribeMember()
{
var data = "memId=" + <?php echo $_SESSION['memberId'];?> + "&actID=" + <?php echo $_GET['actID']; ?> ;
alert(data);
$.ajax({
dataType: 'json',
url: 'json-responses.php?fct=deleteMemberFromActivity',
data: data,
cache: false
});
}
Function is being called properly which is shown by the output of the alert (data); "memId=1600&actID=302"
the json-responses.php file contains these lines to call the dataLayer file:
if ($_GET['fct'] == 'deleteMemberFromActivity')
{
$result = deleteMemberFromActivity($connectionObject, $_GET['actID'], $_GET['memId']);
echo $result;
}
the dataLayer code looks like this:
function deleteMemberFromActivity($PDOdbObject, $actId, $memberId)
{
$deleteSignUpsSQL = "DELETE FROM 'member_activity' WHERE 'activity_id' = ? AND 'member_id' = ?";
$stmt = $PDOdbObject->prepare($deleteSignUpsSQL);
$stmt -> execute([$actId, $memberId]);
$affected_rows = $stmt->rowCount();
return $affected_rows;
}
but when the user clicks on the button, redirect works fine but the deletion in the database does not happen