I have this page with a stop and pause button and I need store user online activity time in minutes on a mysql DB after click on start button. What would be the simplest and most effective way to do this? according to your opinion
Mechanism: The way that I found is send a POST every minute from the hit of button start. If I hit button start and stay on page for 30 minutes this code should add 30 times the value 1 in "timevalue". By this way the total online time will be stored in minutes
Problems: When load page automatically add value 1 on DB, because monitoring.php is loaded together main page
How to assure call the include only after start button click?
How to unload or stop monitor div after stop button?
How to loop this function? setInterval isn't working
counter.php
<?php
//value for test purposes
$result = "get from db"
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>ONLINE TIME</title>
</head>
<script type="text/javascript">
//window.setInterval(function () {executemonitor()}, 1000);
function executemonitor() {
$("#monitor").load("monitoring.php");
}
</script>
<body>
Total Online Time: <?php echo "$result" ?>
<br>
<form method="POST">
<button type="submit" class="start-trigger" onclick="executemonitor()">START</button>
<br><br>
<button class="stop-trigger" onclick="">STOP</input>
<div id="monitor" class="monitoring"><?php include "monitoring.php" ?></div>
</form>
</body>
</html>
monitoring.php
<?php
//set value for test purposes
$timeactivityf = "1";
$servername = "localhost";
$database = "timejob";
$username = "tmj";
$password = "tmj";
$conn = mysqli_connect($servername, $username, $password, $database);
$sql = "INSERT INTO user (timeactivity)
VALUES ('$timeactivityf')";
if (mysqli_query($conn, $sql)) {
// echo "New record has been added successfully !";
} else {
// echo "Error: " . $sql . ":-" . mysqli_error($conn);
}
mysqli_close($conn);
//window.setInterval(function () {executemonitor()}, 1000);
?>
Thanks