Jump to content

storing form varibles page to page


ball420

Recommended Posts

here is my issue.... i have a small shopping cart meaning 20 items, i have it set up now that when you click on an item you go to the next page and the item info shows.

 

Here is the code from the first page

 

<form action="page2.php" method="post">
<input type="hidden" name="item_name" value="A-07">
<input type="hidden" name="amount" value="55.00">
<input type="hidden" name="no_shipping" value="2">
<input type="image" src="SM.gif" border="0" name="submit" >
<img alt="" border="0" src="pixel.gif" width="1" height="1">
</form>

 

what i want to do is to be able to go back to the product pages but still keep that item in the "session" so when you go to the checkout page all those items are there. I understand that i will need to use sessions but how do i differentiate  between items if each item has the same variables within the <form></form>? I hope I'm explaining correctly. Thanks for the guidance it's much appreciated.

 

 

 

 

Link to comment
Share on other sites

The way I'd do it is:

 

 

firstly, start a session in every page, so that as they browse, if a session variable is created, it wont go away if they view a page that doesnt have a session(or changes the current session).

 

I'd make a list of values of the items that were ordered separated by something. One way you can do it is when an item is add to the cart, you do $_SESSION['in_cart'] = $_SESSION['in_cart']."$item_id|";

 

Then when you're going to the "checkout", you'd explode the session variable separating the |'s like..

 

$var = explode("|", $_SESSION['in_cart'])

 

so that the number of items is sizeof($var)-1 (since the last value will be blank, due to the right side of the last | being counted in the array).

Link to comment
Share on other sites

this is what i have,

$_SESSION['mycart']= $_POST['mycart'];."item_name|";

so that I understand the session named 'mycart' will be carried from page to page given that I carry this same session on each page using

 

<?php
session_start();
$_SESSION['mycart']= $_POST['mycart'];."item_name|";
    session_write_close();
?>

 

then each product with the the form name="item_name" will line up when each product is submitted again with the same form name="item_name" but with different values.

 

then at the end when i want to use all the vars collected in the session i use explode.

thanks for your guidance I hope I didn't sound too confusing.

Link to comment
Share on other sites

this is what i have,

$_SESSION['mycart']= $_POST['mycart'];."item_name|";

so that I understand the session named 'mycart' will be carried from page to page given that I carry this same session on each page using

 

<?php
session_start();
$_SESSION['mycart']= $_POST['mycart'];."item_name|";
    session_write_close();
?>

 

then each product with the the form name="item_name" will line up when each product is submitted again with the same form name="item_name" but with different values.

 

then at the end when i want to use all the vars collected in the session i use explode.

thanks for your guidance I hope I didn't sound too confusing.

 

remove the semi-colon after $_POST['mycart']

 

and I'm not positive, but did you have another question? or were you just explaining that you understand whats going on?

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.