Good morning, I'm learning PHP and I've created a login system. I would like help with the code to change the status of the logged in user.
I have a list of users who are online, and when I run this script, I want to change the status of the user who has already spent more than 50 minutes with online status, but he is changing the status of all users.
Here's my code:
$pdo = new PDO("mysql: host=localhost; dbname=pdo","root","");
$view = $pdo->prepare("SELECT agora,lastaccesso FROM users");
$view->execute();
foreach ($view as $mostra):
$lastaccesso = $mostra['lastaccesso'];
$agora = $mostra['agora'];
$horaNova = strtotime("$lastaccesso + 5 minutes");
$horaNovaFormatada = date("H:i", $horaNova);
if ($horaNovaFormatada < $agora):
$altera = $pdo->prepare("UPDATE users SET online='" . $sim_nao . "'");
$altera->execute();
if($altera):
echo "<script>window.location = 'online.php'</script>";
else:
echo "erro";
endif;
endforeach;