Hello,
I would appreciative of any help so I can fix my logout script - I have been spent hours trying work out different things and I need help of possible!!
logout.php
$mysqli = new mysqli('localhost', 'db', 'db', 'db');
# check connection
if ($mysqli->connect_errno) {
echo "<p>MySQL error no {$mysqli->connect_errno} : {$mysqli->connect_error}</p>";
exit();
}
// update status to offline
$sql = "SELECT status from users WHERE id={$_SESSION['username']}";
$result = $mysqli->query($sql);
$user = $result->fetch_array();
$timestamp = $user['status'] - 300;
$sql = "UPDATE users SET status={$timestamp} WHERE id={$_SESSION['username']}";
$result = $mysqli->query($sql);
## finally destroying the session
// unset all session variables
$_SESSION = array();
// destroy the session cookie
if(isset($_COOKIE[session_name()])) {
setcookie(session_name(), '', time()-50000, '/');
}
// destroy the session
session_destroy();
redirect_to("login.php");
?>
I get the following error - Fatal error: Call to a member function fetch_array() on a non-object in /home/www/site/logout.php on line 17
I think what is happening is $user = $result->fetch_array(); returning no information but I am able to display the value of my username in any page which has the session, many thanks for your help in advance!!