Click to See Complete Forum and Search --> : [RESOLVED] Question about Sessions


Megatron
04-01-2006, 11:11 AM
hi, i have a user management system which i want to pull information from the db solely based on the userid field in the database. When the user logs in a session is created which looks as follows:

session_register('userid');
$_SESSION['userid'] = $userid;
session_register('first_name');
$_SESSION['first_name'] = $first_name;
session_register('last_name');
$_SESSION['last_name'] = $last_name;

what would be the code to pull the content from the db?

i'm thinking it would be something like the following, but i'm not sure as this is the first time i have ever used sessions....

if($_SESSION['userid'] == $userid;{
$query = "SELECT * FROM `users";
$result = mysql_query($query);
$rows = mysql_num_rows($result);

}

thanks

intrivious
04-01-2006, 11:47 AM
If I understand you, there are a couple ways:

$query = "SELECT * FROM `users` WHERE userid=".$_SESSION['userid'];

or

$query = "SELECT * FROM `users` WHERE userid='$userid' ";

Should not matter which variable to use. As long as they still hold the same value once you get to this part of your script.

NogDog
04-01-2006, 01:00 PM
There is no need to use session_register() if you are using the $_SESSION array. If fact, as per http://www.php.net/session_register :

Caution

If you are using $_SESSION (or $HTTP_SESSION_VARS), do not use session_register(), session_is_registered(), and session_unregister().

LiLcRaZyFuZzY
04-01-2006, 01:13 PM
Yeah, simply assign the value to it