I’ve made this simple logout script:
<?php
session_start();
$db_connect = mysql_connect('localhost', 'root', '*****');
if(!$db_connect)
{
die('Не може да се осъществи връзка с базата данни' . mysql_error());
}
mysql_select_db("chat", $db_connect);
mysql_query("DELETE FROM activeusers WHERE au_id = '$_SESSION['UserId']'");
mysql_close($db_connect);
session_unset();
session_destroy();
?>
But when I put session_unset() and session_destroy() at the end my editor shows an error with the mysql_query I haven’t tried this yet but I think that probably written this way I empty the $_SESSION array() and thus $_SESSION['UserId'] is destroyed before the query.Am I right here and how should I do it right?
Format your
mysql_query-command like this:This makes sure it is properly embedded into the SQL-part of the command.