jimleeder123 Posted April 22, 2015 Share Posted April 22, 2015 Ok so on the initial page I have auto incremented hidden input box names so it appears like "cart0Pizzas", "cart1Pizzas", "cart2Pizzas" etc. I am posting these to a process page (user won't see this page - is just so i can post the data and store it into sessions. I want to store the appropiate post data into auto incremented sessions. So when the user clicks on the submit button which is in the same form as for example "cart24Pizzas" it will go into $_SESSION['cart0'] if that one isn't set. If it is, then it can go into $_SESSION['cart1']. If that is set, it will go into $_SESSION['cart2'] and so on. How can I do this? Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/295766-auto-increment-sessions/ Share on other sites More sharing options...
ginerjm Posted April 22, 2015 Share Posted April 22, 2015 Don't understand your logic for having this kind of setup. Can you give us some background before we waste time giving you a possible solution that turns out to be unusable? Sounds like you have a commerce site where you want to monitor multiple shopping carts for one user. That doesn't seem right. 1 Quote Link to comment https://forums.phpfreaks.com/topic/295766-auto-increment-sessions/#findComment-1509637 Share on other sites More sharing options...
mentalist Posted April 22, 2015 Share Posted April 22, 2015 if(isset($_SESSION['cart0'])){ or maybe if(empty($_SESSION['cart0'])){ Quote Link to comment https://forums.phpfreaks.com/topic/295766-auto-increment-sessions/#findComment-1509647 Share on other sites More sharing options...
ginerjm Posted April 22, 2015 Share Posted April 22, 2015 Let me pose another question. Just what are these "sessions" you are referring to? Are they truly "PHP Sessions" for which you are trying to make a system to keep track of them all in one session? Because if so, I don't think you can do this since sessions are private and separate for each user by design. Quote Link to comment https://forums.phpfreaks.com/topic/295766-auto-increment-sessions/#findComment-1509654 Share on other sites More sharing options...
gizmola Posted April 22, 2015 Share Posted April 22, 2015 I agree with ginerjm. What are you trying to do and why? Session variables are just like any other type of php variable. You can have a session variable that contains an object or array. Forms can have arrays, i.e.. "lineitem[]" Quote Link to comment https://forums.phpfreaks.com/topic/295766-auto-increment-sessions/#findComment-1509658 Share on other sites More sharing options...
jimleeder123 Posted April 23, 2015 Author Share Posted April 23, 2015 I'm making my own CMS inspired by Joomla/Virtuemart. I've got the products echoed out from the database, each has a hidden field with a name which is auto incremented (0 for first product shown, 1 for the next, 2 for the next etc). What I want to do is to post this info onto a process page, store them into sessions so that I can show the sessions in a cart. Quote Link to comment https://forums.phpfreaks.com/topic/295766-auto-increment-sessions/#findComment-1509758 Share on other sites More sharing options...
ginerjm Posted April 23, 2015 Share Posted April 23, 2015 Your use of the term 'sessions' is confusing. What does it mean? What do you think a session is? It will be forever confusing if you continue to use that term since it is in conflict with PHP's own $_SESSION array and session handling procedures. As for the rest of your description - don't have a clue what you are doing. Why not try and describe it in plain English and leave out the programmer's aspect of your tasks. Quote Link to comment https://forums.phpfreaks.com/topic/295766-auto-increment-sessions/#findComment-1509760 Share on other sites More sharing options...
Muddy_Funster Posted April 23, 2015 Share Posted April 23, 2015 I, like the others that have posted here, just don't get what you're doing here. That should worry you (more that they don't get it than me, but still...). So i'm not sure if it's at all relevent to what you're looking for, but you can do simmilar to the following: $product = array('prd'=>"product1", prdetails=>array("detail1"=>"value1"..."detail[n]"=>"value[n]")); array_push($_SESSION['products'], $product); Quote Link to comment https://forums.phpfreaks.com/topic/295766-auto-increment-sessions/#findComment-1509777 Share on other sites More sharing options...
jimleeder123 Posted April 24, 2015 Author Share Posted April 24, 2015 I haven't had the time to work on my CMS recently and probably won't for a little while but in English ---------- I make products appear on a page according to the category ID in a hidden field sent from the last page. So on the 2nd page all pizzas appear, or all garlic breads appear or all kebabs appear etc. Each product is given a new hidden field which has the product id in. I want to turn this id into a $_SESSION so I can display it in a cart all over the website until the user makes the purchase when the session will be destroyed. Back in programmer language, I have an idea I will try when I next work on this - could I put the posted data into a variable ($foundid = $_POST['hiddenid'] ) and put this in a session? ($_SESSION['.$foundid.'] = $foundid) ?? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/295766-auto-increment-sessions/#findComment-1509816 Share on other sites More sharing options...
Muddy_Funster Posted April 24, 2015 Share Posted April 24, 2015 well that makes a lot more sense! [1]user---[1]shoppingcart--<[many]products is perfectly logical - but you were talking about having [many]shoppingcarts and hat was just weird. Did you look at the code I posted in my last reply? Quote Link to comment https://forums.phpfreaks.com/topic/295766-auto-increment-sessions/#findComment-1509824 Share on other sites More sharing options...
ginerjm Posted April 24, 2015 Share Posted April 24, 2015 So - you are not making multiple 'sessions', you are storing multiple values into a session var. Something like: $_SESSION[$id][] = (something); would create an array of $id elements, each of them having an array of 'somethings' stored. Quote Link to comment https://forums.phpfreaks.com/topic/295766-auto-increment-sessions/#findComment-1509825 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.