Setting session variables from value in database

From: Date: Thu, 13 Mar 2003 21:27:17 +0000
Subject: Setting session variables from value in database
Groups: php.general 
Request: Send a blank email to php-general+get-139604@lists.php.net to get a copy of this message
I have a login page and have sessions working so that if a user is in the database, they can login. I want to also add a "user_type" to the session so that I can have regular staff see certain things, and admin's see other things, but I can't seem to pull the information out of the database. Here is part of what I have. $query = "select * from users where username='$username' and password='$password' "; $result = mysql_query($query); $num = mysql_num_rows($result); $row = mysql_fetch_array($result); $_SESSION['user_type'] = $row['user_type']; $user_type = $_SESSION['user_type']; if ($num > 0 ) { $_SESSION['valid_user'] = $username; $valid_user = $_SESSION['valid_user']; } Now if I tell it to print $valid_user, it shows the user logged in, but if I try to print $user_type I don't get anything in return. Any ideas as to what I am doing wrong? I have tried a separate query for the mysql_fetch_array, and that didn't seem to work either. Mike

« previous php.general (#139604) next »