I posted a question today because i had problem with putting data in database on login, so that i can display the active users in my websites. So it happened to be one "," the problem. But it was suggested to me to use boolean in my database and if the user hasn't logged my bool called 'ifactive = 0'(deffault) , when user logs in 'ifactive=1'. So i made this transition from 0 to 1 on login and will show you part of the code:
if(isset($_POST['submit']))
{
$uname = mysql_escape_string($_POST['uname']);
$pass = mysql_escape_string($_POST['pass']);
$pass = md5($pass);
$sql = mysql_query("SELECT * FROM `userinfo` WHERE `uname` = '$uname' AND `pass` =
'$pass'");
if(mysql_num_rows($sql) > 0) {
mysql_query("UPDATE `userinfo` SET `ifactive` = 1 WHERE `uname` = '$uname'")
or die(mysql_error());
session_start();
$_SESSION['uname'] = $uname;
if (isset($_SESSION['uname'])) {
header('Location: main.php');
}
This part up of the code works correctly, sets the boolean "ifactive" to 1, (this code is in file named login.php, and after login it redirects me to my main page called "main.php". In "main.php" i have put a Logout button, which links to a "logout.php" file where i end the current user session and where i want exactly to reset my boolean "ifactive" to zero:
session_start();
mysql_query("UPDATE `userinfo` SET `ifactive` = 0 WHERE `uname` = '$uname'") or
die(mysql_error());
mysql_close();
session_destroy();
header("Location: index.php ");
But to make this mysql_query work i have to
include 'login.php';
So that i can use the variables. But here comes the main problem. When i include this login.php i suppose the two "Update" codes somehow fight and the second one doesnt work if you understand what i mean. And now i am reading about global variables but am for now confused about them. I mean to make my Update code in Logout.php work i suppose i do not have to include the whole login.php, i want to include only the variables:
$uname
so that it could be recognised