Page 1 of 1

I can't display session variables

Posted: Wed Sep 03, 2008 7:53 pm
by cap2cap10
OK so I know the session array works because if i use print r, I see all data that has been passed to the new page. Now how do I access specific data in the array to place in specific parts of my html.

Here is the sessions array code:

Code: Select all

    $q = "SELECT * FROM `login` WHERE `username` = '".$_SESSION['login_username']."' AND `password` = '".$_SESSION['login_password']."'";
                    $q = mysql_query($q);
                    if(mysql_num_rows($q) == 0) {
                        $_SESSION = array();
                    } else {
                        $ar = mysql_fetch_array($q);
                        $_SESSION['login'] = $ar;
                        $this->LOGGEDIN = true;
                        $this->FAILED = false;
:banghead: Can someone enlighten me on how to display specific data from sessions array.

This:

Code: Select all

<?php print " <b>".$ar['FName'] . "</b> ";?>
does not work

Re: I can't display session variables

Posted: Wed Sep 03, 2008 10:27 pm
by deeessay
Hi the solution to your problem is quite simple. I encountered this when I was just starting out. Just enclose them session variables in curly braces like so:


$q = "SELECT * FROM `login` WHERE `username` = '{$_SESSION['login_username']}' AND `password` = '{$_SESSION['login_password']}'";


and voila! Life's beautiful again! :D

Re: I can't display session variables

Posted: Wed Sep 03, 2008 11:48 pm
by starram
Hello try this

echo $_SESSION['login']['username'];
echo $_SESSION['login']['password'];

When you assign an array to another array it becomes multi-dimentional array.

$_SESSION is an Global Variable and when you store something like this

$_SESSION['login']=1;
Then it becomes an array & when you assign an array to it it becomes multi-dimentional array.

This will surely help you and clear your concept about it.