katten
01-15-2006, 05:05 PM
o well when they loggin i try and add 1 to status and when they logg out i do -1 but it ain't working ill post the codes then i gotta go to bed .. :( School... :mad:
Login
<?
session_start();
mysql_connect("localhost","katten","katten");
mysql_select_db("neverland");
$name = $_POST["user"];
$password = $_POST["password"];
if(empty($name) or empty($password)){
header("location: index.php?login=form_empty");
} else {
$result = mysql_query("SELECT access,name FROM members WHERE name = '$name' and password = '$password'") or die(mysql_error());
$ok = mysql_num_rows($result);
if ($ok == 1){
mysql_query("UPDATE members SET status=status+1 WHERE name = '$user'") or die (mysql_error());
$_SESSION["login"] = true;
$_SESSION["user"] = "$name";
$_SESSION["password"] = "$password";
$_SESSION['access'] = mysql_result($result, 'access');
header("location: index.php?login=true");
}
else{
header("location: index.php?login=wrong");
}
}
?>
and now logout.php
<?php
session_start();
$user = $_SESSION["user"];
mysql_connect("localhost","katten","katten");
mysql_db_query("neverland","UPDATE members SET status=status-1 WHERE name = '$user'") or die (mysql_error());
session_unset();
header("location: index.php");
?>
Login
<?
session_start();
mysql_connect("localhost","katten","katten");
mysql_select_db("neverland");
$name = $_POST["user"];
$password = $_POST["password"];
if(empty($name) or empty($password)){
header("location: index.php?login=form_empty");
} else {
$result = mysql_query("SELECT access,name FROM members WHERE name = '$name' and password = '$password'") or die(mysql_error());
$ok = mysql_num_rows($result);
if ($ok == 1){
mysql_query("UPDATE members SET status=status+1 WHERE name = '$user'") or die (mysql_error());
$_SESSION["login"] = true;
$_SESSION["user"] = "$name";
$_SESSION["password"] = "$password";
$_SESSION['access'] = mysql_result($result, 'access');
header("location: index.php?login=true");
}
else{
header("location: index.php?login=wrong");
}
}
?>
and now logout.php
<?php
session_start();
$user = $_SESSION["user"];
mysql_connect("localhost","katten","katten");
mysql_db_query("neverland","UPDATE members SET status=status-1 WHERE name = '$user'") or die (mysql_error());
session_unset();
header("location: index.php");
?>