Reputation: 1
I'm a novice programmer and I already googled around but nothing suitable was found. I need to update my MySql table after the user quit the system. I have done update to "Y" status, when the user logs in, however on my logout.php file, the update statement does not setting "N" status when the user quits. Please could some of you give a hand? Thanks
Here my code:
<?php
$db = new PDO 'mysql:host=localhost;dbname=name;charset=utf8', 'user', 'password');
$sql = $db->exec("UPDATE 'tb_user'
SET 'flag_logged' = 'N'
WHERE user_id =".$_SESSION['userid']);
echo $sql .' were affected';
session_destroy();
header('location: index.php');
?>
Upvotes: 0
Views: 768
Reputation: 368
I realized there are some few typos in your code. You missed an opening bracket of the PDO Constructor.
Take a look this code.
$user_id = $_SESSION['userid'];
$db = new PDO('mysql:host=localhost;dbname=name;', 'user', 'password');
$sql = "UPDATE `tb_user SET `flag_logged` = 'N' WHERE id = :id";
$statement = $db->prepare($sql);
$statement->execute(['id'=>$user_id]);
session_destroy();
header('Location: index.php');
Upvotes: 1