This topic is locked
[SOLVED]

 Sessions variables

7/2/2011 11:53:39 AM
PHPRunner General questions
R
rocknroll_france author

Hi,

Could you please help me on the sessions variables ?

On the Login page, on the "After successful login" event, I have the following code:
global $conn;

$strSQL = "SELECT tb_mdp.id, tb_mdp.club FROM tb_mdp WHERE tb_mdp.password = 'rdap6756'";

$rs = db_query($strSQL,$conn);

while ($data = db_fetch_array($rs))

$_SESSION["IdClub"]=$data["id"];

$_SESSION["NomClub"]=$data["club"];
If I make a var_dump($_SESSION)in one another page, I have:

'IdClub' => string '19' (length=2)

'NomClub' => null
If I switch the 2 variables on the login page:

$_SESSION["NomClub"]=$data["club"];

$_SESSION["IdClub"]=$data["id"];
The dump shows me only the 1st ($_SESSION["NomClub"]), the 2nd variable is set to null....
Is it not possible to have more than 1 session variable ? Or may be I forgot something ?
Nice WE to all,

C
cgphp 7/2/2011

If the query result will be only one (LIMIT 1 can help you):

global $conn;

$strSQL = "SELECT id, club FROM tb_mdp WHERE password = 'rdap6756'";

$rs = db_query($strSQL,$conn);

$data = db_fetch_array($rs);

$_SESSION["IdClub"]=$data["id"];

$_SESSION["NomClub"]=$data["club"];


If the query returns more than one record you need a multi dimensional array:

global $conn;

$strSQL = "SELECT id, club FROM tb_mdp WHERE password = 'rdap6756'";

$rs = db_query($strSQL,$conn);

$i = 0;

while ($data = db_fetch_array($rs))

{

$_SESSION["IdClub"][$i] = $data["id"];

$_SESSION["NomClub"][$i] = $data["club"];

$i++;

}
R
rocknroll_france author 7/2/2011

Thanks for this quick answser Christian

I try and post.

Have a nice WE.

R
rocknroll_france author 7/2/2011

Works fine

You save my Week End <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=59178&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />