Re: Setting session variables from value in database

From: Date: Thu, 13 Mar 2003 21:46:47 +0000
Subject: Re: Setting session variables from value in database
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-139610@lists.php.net to get a copy of this message
are you sure that $row['user_type'] has a (non-null) value? "Mike Tuller" <php@ce.anoka.k12.mn.us> wrote in message news:90D66B09-559A-11D7-8D2C-0003938E6950@ce.anoka.k12.mn.us... > 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 (#139610) next »