flit Posted April 13, 2008 Share Posted April 13, 2008 Hi there, I am trying to add id's to a session, but when I click on a link to enter the id into the session, it overwrites it and does not add an id to the session. I have a page called 6.php with the following lines: <a href="7.php<? php session_start(); $_SESSION['id']='1';?>">Test 1</a> -->writes to the session: id|s:1:"1"; <br> <a href="7.php<? php session_start(); $_SESSION['id']='2';?>">Test 2</a> -->writes to the session: id|s:1:"2"; I want to be able to add an id into the session and not overwrite it. Can anyone help me? Quote Link to comment Share on other sites More sharing options...
p2grace Posted April 13, 2008 Share Posted April 13, 2008 Try this: <a href="7.php<? php session_start(); $_SESSION['id'][] ='1';?>">Test 1[/url] -->writes to the session: id|s:1:"1"; <a href="7.php<? php session_start(); $_SESSION['id'][]='2';?>">Test 2[/url] -->writes to the session: id|s:1:"2"; You need to treat it like an array Quote Link to comment Share on other sites More sharing options...
flit Posted April 13, 2008 Author Share Posted April 13, 2008 Thanks dude, it worked! Another id was added to the session. Can I use the foreach statement later to retrieve data from a database like they are stored? -> id|a:4:{i:1;s:1:"1";.........;} Quote Link to comment Share on other sites More sharing options...
flit Posted April 13, 2008 Author Share Posted April 13, 2008 I can't add the same id to the session more than once Quote Link to comment Share on other sites More sharing options...
flit Posted April 13, 2008 Author Share Posted April 13, 2008 When I added some more links, the program writes the id of the last link to the session thus 8 <a href="7.php<? php session_start(); $_SESSION['id']='1';?>">Test 1[/url] <a href="7.php<? php session_start(); $_SESSION['id']='2';?>">Test 2[/url] <a href="7.php<? php session_start(); $_SESSION['id']='3';?>">Test 3[/url] <a href="7.php<? php session_start(); $_SESSION['id']='8';?>">Test 8[/url] Help? Quote Link to comment Share on other sites More sharing options...
p2grace Posted April 13, 2008 Share Posted April 13, 2008 Where are the id's coming from, and what exactly is it that you want it to do? You say that right now it's writing the id of the last link, what is it supposed to do? Quote Link to comment Share on other sites More sharing options...
p2grace Posted April 13, 2008 Share Posted April 13, 2008 BTW you can use a foreach statement later to view the ids in the session. Quote Link to comment Share on other sites More sharing options...
flit Posted April 13, 2008 Author Share Posted April 13, 2008 When I press the first link I want to write 1 to the session file but when I press 1 it writes 8 to the session file When I press the second link I want to write 2 to the session file but when I press 2 it writes 8 to the session file When I press the third link I want to write 3 to the session file but when I press 3 it writes 8 to the session file I want my session file to look like this: 1,2,3,8....... I used to do this with <a href="99.php?action=add&id=1">Add id 1 to session</a> but I don't want to use that technique. I don't want the action=add&id=1 message printed in my web browser. I want to add id's like the links below. <a href="7.php<? php session_start(); $_SESSION['id']='1';?>">Test 1[/url] <a href="7.php<? php session_start(); $_SESSION['id']='2';?>">Test 2[/url] <a href="7.php<? php session_start(); $_SESSION['id']='3';?>">Test 3[/url] <a href="7.php<? php session_start(); $_SESSION['id']='8';?>">Test 8[/url] All I want to do is insert a id value into a session by clicking on a link, and retrieve the id's later to print some mysql info on a page Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.