Hi all,
I have an app with cart functionality. Some pages showcase items and from these pages you can add item(s) to the cart.
All of these "product pages" have the session_start() command at the top of the page.
Other pages are not product oriented, just informational - such as company history.
I just wish to confirm - get feedback from the group here that I have developed a good approach.
On the product pages, when a "add to cart" button is clicked I send the app to "update_cart.php" Users don't see this because it redirects back to the page they came from. But on the update_cart.php page I have this snippet:
session_start();
if(!isset($_SESSION['cart'])){
$ssql="Select Max(CartID) from tblCarts";
$result=mysql_query($ssql,$connection) or die ('unable to get maxcart');
$row=mysql_fetch_row($result);
$row[0]=$row[0]+1;
$_SESSION['cart']=$row[0];
}
So - at anytime the first item is added to the cart - that is when the session starts.
My questions are
1) is this a good approach - it forces a new cart to start upon the first item being selected, and
2) should I have the session_start() line on every page - such as the company history page? Or just keep it on the product pages.
I might even be mistaken that I need the session_start() on the product pages at all! Perhaps the update_cart.php is the only place where any session code is needed.
Thanks for any help!
- KB
I have an app with cart functionality. Some pages showcase items and from these pages you can add item(s) to the cart.
All of these "product pages" have the session_start() command at the top of the page.
Other pages are not product oriented, just informational - such as company history.
I just wish to confirm - get feedback from the group here that I have developed a good approach.
On the product pages, when a "add to cart" button is clicked I send the app to "update_cart.php" Users don't see this because it redirects back to the page they came from. But on the update_cart.php page I have this snippet:
session_start();
if(!isset($_SESSION['cart'])){
$ssql="Select Max(CartID) from tblCarts";
$result=mysql_query($ssql,$connection) or die ('unable to get maxcart');
$row=mysql_fetch_row($result);
$row[0]=$row[0]+1;
$_SESSION['cart']=$row[0];
}
So - at anytime the first item is added to the cart - that is when the session starts.
My questions are
1) is this a good approach - it forces a new cart to start upon the first item being selected, and
2) should I have the session_start() line on every page - such as the company history page? Or just keep it on the product pages.
I might even be mistaken that I need the session_start() on the product pages at all! Perhaps the update_cart.php is the only place where any session code is needed.
Thanks for any help!
- KB