I want to send a value to the database when the user closes the page such as online and offline , I hope to find the solution I have tried for more than 7 hours But does not work
<script tysssspe="text/javascript">
//ST
window.onbeforeunload = function(){
var user_st = "0";
$.ajax({
type:"POST",url:"inc/offline.php",
data:"user_st="+user_st
});
}
//SD
</script>
To offline.php
<?php
tab
include "connect.php";
$UID = $_COOKIE["ID"];
$online_status = $_POST['user_st'];
$setStatus = $conn->prepare("UPDATE accounts SET online = :online_status WHERE id = :UID");
$setStatus->bindParam(':online_status',$online_status,PDO::PARAM_INT);
$setStatus->bindParam(':UID',$UID,PDO::PARAM_INT);
$setStatus->execute();
?>