decessus Posted March 9, 2006 Share Posted March 9, 2006 Hi guys,I am working on a webshop application and I kind of got stuck making my shopping cart. I want to save the products users order by using sessions. Once the user clicked 'order', 2 vars should be saved, one called 'id' and the other called 'count'. ID will be read out of $_GET['id'], and count will have a standard number, '1'. (Users will be able to change this amount later).I have no clue how to save multiple vars in a session, and later print em. I think I have to use a for loop, but since I am pretty new at using sessions; and most of the stuff I read is either outdated or wrong (might be me though ;)), I ask you for your help.Thanks in advance,-Dec Quote Link to comment Share on other sites More sharing options...
lessthanthree Posted March 9, 2006 Share Posted March 9, 2006 [!--quoteo(post=353183:date=Mar 9 2006, 08:10 AM:name=decessus)--][div class=\'quotetop\']QUOTE(decessus @ Mar 9 2006, 08:10 AM) [snapback]353183[/snapback][/div][div class=\'quotemain\'][!--quotec--]Hi guys,I am working on a webshop application and I kind of got stuck making my shopping cart. I want to save the products users order by using sessions. Once the user clicked 'order', 2 vars should be saved, one called 'id' and the other called 'count'. ID will be read out of $_GET['id'], and count will have a standard number, '1'. (Users will be able to change this amount later).I have no clue how to save multiple vars in a session, and later print em. I think I have to use a for loop, but since I am pretty new at using sessions; and most of the stuff I read is either outdated or wrong (might be me though ;)), I ask you for your help.Thanks in advance,-Dec[/quote]To register session variables you need to add values to the $_SESSION supergobal.To do this...[code]<?phpsession_start(); //this must go at the top of every page you need to use the vars on BEFORE even html code)//put the values into the session vars$_SESSION["id"] = $id;$_SESSION["count"] = 1;[/code]You can then access the values at any time by treating th $_SESSION supergobal as you would any other array. Quote Link to comment Share on other sites More sharing options...
bahewitt Posted January 1, 2009 Share Posted January 1, 2009 Hi DecI had a similar problem with a blog site I'm developing.My URL was something like:edit_post.php?post_id=9&action=addThe submit button was set to:edit_post.phpBut when you reload the page the variables were lost as the new page was loaded.If you want to have the variables available on an additional page you can assign them to a variable within your script, in my case I assigned $post_id=$_GET['post_id];Then on the submit button set action to:edit_post.php?post_id=<?php echo $post_id?>&action=addAnd you get to carry your variable assigned to the value through the page.Hope this helps, and if there is a better way I would love to hear about itRegardsBruce 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.