Page 1 of 1
$_SESSION variables
Posted: Sun Mar 27, 2005 4:19 pm
by anthony88guy
Does php allow you to do this? When i try retrieving the values they come up as 0.
Posted: Sun Mar 27, 2005 4:25 pm
by John Cartwright
It is valid to do so, but I don't really see much of a reason aside from poor implementation of why you need sessions for this.
What show us where you are trying to retrieve their values, perhaps thats where you error lies.
Posted: Sun Mar 27, 2005 4:27 pm
by anthony88guy
When you login, it retrieves these values, then when certain pages request them they are all ready avaliable. Is their a better way to do this?
Posted: Sun Mar 27, 2005 4:34 pm
by John Cartwright
you are performing the query, but never retrieving the values.
Code: Select all
$result = mysql_query("SELECT * FROM users WHERE user = '$user' LIMIT 1") or die(mysql_error());
$row = mysql_fetch_assoc($result);
$_SESSION['strikeaction'] = $row['strikeaction'];
$_SESSION['armysize'] = $row['armysize'];
Posted: Sun Mar 27, 2005 7:08 pm
by anthony88guy
thanks, all works now.
Posted: Sun Mar 27, 2005 7:08 pm
by feyd
those results are basically null and void once the page has finished parsing, unless you are using a persitant connection.. and even then, they could be cleared from memory.
Posted: Sun Mar 27, 2005 9:33 pm
by anthony88guy
so your saying each time i need those values i should connect to the database and get them?
Posted: Sun Mar 27, 2005 10:48 pm
by John Cartwright
basically you should only run these values under certain curcomstances only.
The main reason is that the values will be overwritten unless you consitantly have $user set to a valid user or else your session values become null.