1
Good morning, I am learning PHP and created a login system. I would like help with the code to change the status of logged in user.
I have a list of users who are online and, when running this script, I wanted to change the status of the user who has already spent more than 50 minutes with online status, only he is changing the status of all users.
This is 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;
Voce is setting this variable $sim_nao somewhere?
– Ademilson Santana da Silva
Apparently you’re not closing the first
if
– fernandosavio
I had forgotten the variable and the if , already put and the result is the same . it changes status of all users , but I just want it to be landed from users who are more than 1 hour with online status
– Sergio Silva
tried this code but is returning me error .
– Sergio Silva
$con=mysqli_connect("localhost","root",""","Pdo"); if (mysqli_connect_errno()) { echo "Failed to connect to Mysql: " . mysqli_connect_error(); } $result = mysqli_query($con,"SELECT id_user, TIMEDIFF(lastaccess,now) AS diff FROM users"); $Row = mysqli_fetch_array($result); $sim_nao = ($Row["diff"] > 10) ? '0' : '1'; mysqli_query($con,"UPDATE users SET online='". $sim_nao." 'Where differs >= -00:25:18"); mysqli_free_result($result); mysqli_close($con); ?>
– Sergio Silva
mysqli_fetch_array() expects Parameter 1 to be mysqli_result, Boolean Given in
– Sergio Silva