Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Re: [PHP-DB] Forms submitting to a session array
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.

<?php
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/

Report this thread to moderator Post Follow-up to this message
Old Post
Chris
01-14-08 12:00 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP DB archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 09:00 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.