I use sessions on my site to authenticate and as well as show that the user is logged in and such. I use them in the standard way, when a use logges in I set a session variable called loggedin to a value of 1. Also I set an id varialbe that i refrence in other scripts.
I also use databases quite extensively, and a popular field is id. So when I get that value, I use something like this..
$sql = "SELECT id FROM table WHERE condition"
$result = mysql_query($sql);
$id = mysql_result($result , 0);
That last line of code is where things get messed up. What was happening was the session varialbe id keeps getting reset to the value of the mysql call. to test for this I created a really easy script...
echo " Session 1:" . $_SESSION['id'];
$id = 123;
echo " Echoed Id:" . $id;
echo " Session 2:" .$_SESSION['id'];
RESULTING OUTPUT:
Session 1: 5028
Echoed Id: 123
Session 2: 123
Why does id get reset without an explicit call to $_SESSION['id']??