Click to See Complete Forum and Search --> : sql problems with status on login/logout


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");
?>

chazzy
01-15-2006, 07:51 PM
what's the default value of status? this won't work if status starts off NULL, but will work if status starts off as 0.

katten
01-16-2006, 09:34 AM
:S its working now i was using varchar not INT thats was the problem so now it working :P

katten
01-16-2006, 12:34 PM
the problem is now of setting 1 as max and 0 as min how :P?

chazzy
01-16-2006, 01:37 PM
you could make column type enum(0,1) but then you'd have to change how your logout/login works (on login set the value=1 and on logout set the value=0)

katten
01-16-2006, 03:08 PM
how do i set enum 0,1 :S and allso must i change the update sql code :P?
im still noob :D

chazzy
01-16-2006, 03:26 PM
you alter the column type to be enum with values 0,1.
yes you have to modify the update code.

katten
01-17-2006, 11:09 AM
yea i know how to alter the colum but not set the values 0,1 and allso whats should my code be then :S