"Add to cart" function, need help...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
WithHisStripes
Forum Contributor
Posts: 131
Joined: Tue Sep 13, 2005 7:48 pm

"Add to cart" function, need help...

Post by WithHisStripes »

Heya,
So I need to build a VERY simple "add to cart" function but I don't know where to begin. What I have is a site that has four pop up JS windows with just a few products. What I want to do is have a check box next to each product within each window and then a "add to cart" button at the bottom of the page. I need that button to send the titles of the checked boxes (ie shirt, cd, book, etc...) to another page on the site where they can view their order, after that, I know what to do. Can anyone help?! Thanks!

-Spence
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Use sessions to send the variables from page to page.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

suggestion: don't use popups.

an "add to cart" link/button/whatever most often simply stores the product(s) id(s) (maybe a quantity, a size, whatever else) into an order items table that is associated with an order record.
WithHisStripes
Forum Contributor
Posts: 131
Joined: Tue Sep 13, 2005 7:48 pm

Post by WithHisStripes »

Thanks guys for the input, I understand that pop ups aren't the best way to do it, but I'd like to give it a try if it's possible. Now, about using sessions, I understand php code pretty easily but I don't write it well, so really, I don't know where to begin in writing the code, could you give me an example code or maybe point me to some resources? Thanks SO much guys!

-Spence
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Simple sessions test:

Code: Select all

page1.php


<?php
session_start();

$_SESSION['MY_COUNTER']++;


echo 'Counter: ' . $_SESSION['MY_COUNTER'];

?>

<a href="page2.php">Page 2</a>

Code: Select all

page2.php


<?php
session_start();

$_SESSION['MY_COUNTER']++;


echo 'Counter: ' . $_SESSION['MY_COUNTER'];

?>


<a href="page1.php">Page 1</a>
WithHisStripes
Forum Contributor
Posts: 131
Joined: Tue Sep 13, 2005 7:48 pm

Post by WithHisStripes »

Okay, so if I am right, those pages are sharing information with each other via the mycounter session. And mycounter acts as the cookie by storing their order?
Now how do I create the page where that information is stored? Thanks!
Post Reply