Page 1 of 1

Getting user information, need some assistance.

Posted: Wed Aug 19, 2009 1:28 pm
by synical21
Ive done my user managment system for my site and now i want to bring back some information from the database to the webpage. So far i have only managed to get one to work which is:

Code: Select all

<? echo $_SESSION['user_name'];?>


Obviously that displayed the current username.

Now i want to do the same method but with the ID of the user. In the MySQL table its under "id" so i tried:

Code: Select all

<? echo $_SESSION['id'];?>
but no luck, i have a feeling it has something to do with this piece of code in the script

Code: Select all

 
<? if (isset($_SESSION['user_id'])) {?>
Im still learning stuff like this from tutorials which is why im really sketchy on the code. Any assistance not only helps me but also allows me to understand php more.

Re: Getting user information, need some assistance.

Posted: Wed Aug 19, 2009 3:15 pm
by califdon
Just to make sure you interpret McInfo's explanation correctly, let me rephrase it: $_SESSION variables only contain what YOUR SCRIPT stores there. Until and unless you assign a $_SESSION variable, it doesn't exist. Other global variables, such as $_SERVER, for instance, have values set by the server or other sources, but $_SESSION is your baby. It will only contain what YOU put there.

Re: Getting user information, need some assistance.

Posted: Wed Aug 19, 2009 3:48 pm
by reddurango
I think you can do a query in the database with the user name, and then with a while loop assign the value of the $_SESSION variable. And i got a question for you, i tried to use this method for my user management system but i can get the SESSION variable surf trough my pages when i try to use it agan it is on 0.

Re: Getting user information, need some assistance.

Posted: Wed Aug 19, 2009 4:19 pm
by synical21
This is what ive done, this is the query(in login.php):

Code: Select all

$sql = "SELECT `id`,`full_name`,`approved` FROM users WHERE 
           $user_cond
            AND `pwd` = '$md5pass' AND `banned` = '0'
            "; 
 
and here is the variables:

Code: Select all

session_start(); 
       // this sets variables in the session 
        $_SESSION['user_id']= $id;  
        $_SESSION['user_name'] = $full_name;
then on another page (account.php) i enter

Code: Select all

<? echo $_SESSION['user_id'] ;?>
to hopefully show the current user ID, but for somereason it shows the username :S


... 2min later as i recheck my scripts inbetween writing this post it works. Weird lol ill post it anyways.

Thanks for the help.