Jump to content

Recommended Posts

For the following code, when the link is clicked, what will the session be storing exactly? I'm trying to do this on multiple pages, with different product_id's, so when clicked they will be held in a session and then I can display them in a shopping cart. Will this work?

 

<?
session_start();
if (!isset($_SESSION['cart'])) {
$_SESSION['cart'] = array();
}
if (isset($_GET['buy'])) {
$_SESSION['cart'][] = $_GET['product_id'];
}
?>

 

<form method="post" name="itemselect" action="<? echo "$_SERVER[php_SELF]?product_id={$id}" ?>" target="purchaseform">

Link to comment
https://forums.phpfreaks.com/topic/85432-solved-sessions/
Share on other sites

product_id=$id isn't added?

 

What I want to do is add multiple product_id's to a "cart" and then have the user be able to view the products they've added (all the products and their id's are in my database.) I have the session counting how many products are in the cart, and it's working, I'm just not sure how to "extract" the product_id information from the session.

 

Could someone explain?

Link to comment
https://forums.phpfreaks.com/topic/85432-solved-sessions/#findComment-435888
Share on other sites

Well $_SESSION['cart'] is an array. You can loop though it or access by specific key.

 

for example

foreach($_SESSION['cart] as $key => $val){

echo 'key: ' . $key .' val:' . $val . '<br />';

}

 

I dont know what type of query you are trying to run, but that should be how you access the info

Link to comment
https://forums.phpfreaks.com/topic/85432-solved-sessions/#findComment-435903
Share on other sites

Ahh, okay.

 

Could I keep the rest of my SELECT statement, or would I need to change it (I need each product_id to apply to the statement.)

 

$query = mysql_query("SELECT * 
FROM feature_product, feature_group, feature_item 
WHERE feature_product.feature_product_id IN (". $product_ids .") 
AND feature_group.feature_product_id=feature_product.feature_product_id 
AND feature_item.feature_group_id=feature_group.feature_group_id");

Link to comment
https://forums.phpfreaks.com/topic/85432-solved-sessions/#findComment-435951
Share on other sites

Nevermind, figured that one out.

 

BUT, now no matter which product I add (product_id=2&product_buy=2, for example) it just shows the first product again (product_id=1&product_buy=1). I think this has to do with the implode, but I don't know how it works.

 

Anyone?

Link to comment
https://forums.phpfreaks.com/topic/85432-solved-sessions/#findComment-435974
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.