Jump to content

Auto increment sessions


jimleeder123

Recommended Posts

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.

Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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[]"

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.