Forms submitting to a session array

Forms submitting to a session array

am 13.01.2008 22:12:40 von thomas

I'm trying to create a shopping cart where users can visit a product pag=
e =

(called from a MySQL database depending on the url ending in =

?product_id=3D#). On the product page users can select options from drop=
down =

lists (such as color, etc.) These dropdown lists are also dynamically =

generated from the database.

I need to store what the user has selected while the user browses the =

site. I want to also display what they've selected on a "cart" page.

I believe my best option is to store what they've selected in a session =
=

array. I'm not sure how to do this with the dropdown lists, etc.

Any help would be greatly appreciated!

-- =

Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Forms submitting to a session array

am 14.01.2008 00:04:33 von dmagick

Thomas wrote:
> I'm trying to create a shopping cart where users can visit a product
> page (called from a MySQL database depending on the url ending in
> ?product_id=#). On the product page users can select options from
> dropdown lists (such as color, etc.) These dropdown lists are also
> dynamically generated from the database.
>
> I need to store what the user has selected while the user browses the
> site. I want to also display what they've selected on a "cart" page.
>
> I believe my best option is to store what they've selected in a session
> array. I'm not sure how to do this with the dropdown lists, etc.

In exactly the same way as any other data. If you want to save it
per-product, you could do something like this.

session_start();

if (empty($_SESSION['products'])) {
$_SESSION['products'] = array();
}

// appropriate checking for form submission here.
// and also making sure proper colors or whatever are posted.
// ....

$session_product = array();
$session_product['product_id'] = $_POST['product_id'];
$session_product['color'] = $_POST['color'];

// add the new array of info to the session.
array_push($_SESSION['products'], $session_product);


now if you print_r($_SESSION['products']) you'll see a big array of info
with each product having a color.


--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php