Freedom-n-Democrazy Posted October 7, 2011 Author Share Posted October 7, 2011 It now adds X ammount of products I add, but it still fails to update. Here is the code for the entire process as it stands: /(product)/index.html <FORM action="../../../../cart/addtocart.html" method="post" name="form"> <DIV> Add <TEXTAREA class="quantity" cols="0" name="quantity" rows="0"> </TEXTAREA> <SELECT class="size" name="size"><OPTION>Large</OPTION></SELECT> to <INPUT class="cart" type="submit" value="CART"><INPUT class="id" name="id" type="hidden" value="<?php echo $id; ?>"> </DIV> </FORM> cart/addtocart.html <?php $quantity = $_POST['quantity']; $size = $_POST['size']; $id = $_POST['id']; $item_found = false; foreach ($_SESSION['cart']['content'] as $key=>$product) { if ($product['id'] == $id) { $item_found = $key; break; } } if ($item_found !== false) { $_SESSION['cart']['content'][$item_found]['$quantity'] = $_SESSION['cart']['content'][$item_found]['$quantity'] + $quantity; echo "Quantity updated"; } else { $_SESSION['cart']['content'][] = array ('quantity' => $quantity, 'size' => $size, 'id' => $id); echo "Added."; } ?> cart/index.html $query = "select * from products where id='{$content['id']}'"; $result = mysql_query($query); $row = mysql_fetch_array($result); echo ' <DIV class="cartproduct"> <IMG alt="" src="../products/'.$row['fordir'].'/'.$row['categorydir'].'/'.$row['id'].'/thumbnail.png"> <DIV class="cartproductdata"> <B>Product ID:</B> '.$content['id'].' <BR> <B>Size:</B> '.$content['size'].' <BR> <B>Price:</B> $'.$row[price].' AUD <BR> <B>Quantity:</B> '.$content['quantity'].' <BR> <BR> <INPUT type="submit" value="REMOVE FROM CART"> </DIV> </DIV> '; Link to comment https://forums.phpfreaks.com/topic/248624-remvoing-an-object-from-_session/page/2/#findComment-1276929 Share on other sites More sharing options...
Buddski Posted October 7, 2011 Share Posted October 7, 2011 $_SESSION['cart']['content'][$item_found]['$quantity']?? should be $_SESSION['cart']['content'][$item_found]['quantity'] Link to comment https://forums.phpfreaks.com/topic/248624-remvoing-an-object-from-_session/page/2/#findComment-1276934 Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 7, 2011 Author Share Posted October 7, 2011 The line now sits at: $_SESSION['cart']['content'][$item_found]['$quantity'] = $_SESSION['cart']['content'][$item_found]['quantity'] + $quantity; .. but still the same behavior... > A product can add, but cannot update. Link to comment https://forums.phpfreaks.com/topic/248624-remvoing-an-object-from-_session/page/2/#findComment-1276938 Share on other sites More sharing options...
Buddski Posted October 7, 2011 Share Posted October 7, 2011 $_SESSION['cart']['content'][$item_found]['$quantity']?? should be $_SESSION['cart']['content'][$item_found]['quantity'] You did it twice... Link to comment https://forums.phpfreaks.com/topic/248624-remvoing-an-object-from-_session/page/2/#findComment-1276939 Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 7, 2011 Author Share Posted October 7, 2011 Buddski it worked bro! Thanks Tomorrow I am gonna work on the removing part. That I will be able to figure out myself with this new code flow. Its familiar now I understand WTF is going on. Do you have Facebook? Your my age and from VIC aswell and seem to enjoy computers as do I. Send me a PM and I'll add ya. I'm going to bed man, I am Fd! running around the CBD all day over absolute BS. TTYL Link to comment https://forums.phpfreaks.com/topic/248624-remvoing-an-object-from-_session/page/2/#findComment-1276943 Share on other sites More sharing options...
AyKay47 Posted October 7, 2011 Share Posted October 7, 2011 Buddski it worked bro! Thanks Tomorrow I am gonna work on the removing part. That I will be able to figure out myself with this new code flow. Its familiar now I understand WTF is going on. Do you have Facebook? Your my age and from VIC aswell and seem to enjoy computers as do I. Send me a PM and I'll add ya. I'm going to bed man, I am Fd! running around the CBD all day over absolute BS. TTYL psyco stalker... Link to comment https://forums.phpfreaks.com/topic/248624-remvoing-an-object-from-_session/page/2/#findComment-1276947 Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 7, 2011 Author Share Posted October 7, 2011 AyKay47 you mad bro? Link to comment https://forums.phpfreaks.com/topic/248624-remvoing-an-object-from-_session/page/2/#findComment-1276949 Share on other sites More sharing options...
AyKay47 Posted October 7, 2011 Share Posted October 7, 2011 not at all... just stating the obvious.. Link to comment https://forums.phpfreaks.com/topic/248624-remvoing-an-object-from-_session/page/2/#findComment-1276950 Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 7, 2011 Author Share Posted October 7, 2011 Why you mad bro? Link to comment https://forums.phpfreaks.com/topic/248624-remvoing-an-object-from-_session/page/2/#findComment-1276953 Share on other sites More sharing options...
Buddski Posted October 7, 2011 Share Posted October 7, 2011 Buddski it worked bro! Thanks Tomorrow I am gonna work on the removing part. That I will be able to figure out myself with this new code flow. Its familiar now I understand WTF is going on. Do you have Facebook? Your my age and from VIC aswell and seem to enjoy computers as do I. Send me a PM and I'll add ya. I'm going to bed man, I am Fd! running around the CBD all day over absolute BS. TTYL psyco stalker... Hahahahaha... Link to comment https://forums.phpfreaks.com/topic/248624-remvoing-an-object-from-_session/page/2/#findComment-1276961 Share on other sites More sharing options...
AyKay47 Posted October 7, 2011 Share Posted October 7, 2011 buddski you want to meet up sometime and get drinks? whats your address and zip? Link to comment https://forums.phpfreaks.com/topic/248624-remvoing-an-object-from-_session/page/2/#findComment-1276966 Share on other sites More sharing options...
Buddski Posted October 7, 2011 Share Posted October 7, 2011 Who's paying? Link to comment https://forums.phpfreaks.com/topic/248624-remvoing-an-object-from-_session/page/2/#findComment-1276972 Share on other sites More sharing options...
AyKay47 Posted October 7, 2011 Share Posted October 7, 2011 I guess I will.. Link to comment https://forums.phpfreaks.com/topic/248624-remvoing-an-object-from-_session/page/2/#findComment-1276975 Share on other sites More sharing options...
Buddski Posted October 7, 2011 Share Posted October 7, 2011 Im good with that. Link to comment https://forums.phpfreaks.com/topic/248624-remvoing-an-object-from-_session/page/2/#findComment-1276976 Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 8, 2011 Author Share Posted October 8, 2011 AyKay47, it sounds like you don't have much experience in life. I suspect your one of those womanless losers that has spent their entire social life on SourceForge and Warhammer 10 000 forums. Sup Buddski, When I add 1 size Large to a SESSION, it adds fine... When I had another 3 size Large to the SESSION, it adds onto 1 fine and becomes 4... but when I add 1 size Small, it adds onto the same entity in the session and becomes 5. Now that my brains functioning again, I checked out the code you suggested and I think I can see why its happening: The action to add to the SESSION is: foreach ($_SESSION['cart']['content'] as $key=>$product) { if ($product['id'] == $id) { $item_found = $key; ... I think its happening because the key is just the id, and I think what needs to be done is also make the key the size? I tried this, but it didn't work: foreach ($_SESSION['cart']['content'] as $key=>$product,$size) { if ($product['id'] == $id && $product['size'] == $size) { $item_found = $key; ... am I going the right way about it? Like, with the key being the id and the size or am I tripping? lol Link to comment https://forums.phpfreaks.com/topic/248624-remvoing-an-object-from-_session/page/2/#findComment-1277128 Share on other sites More sharing options...
Philip Posted October 8, 2011 Share Posted October 8, 2011 Let's keep it on-topic guys. FYI, Freedom - next time I'd suggest having that conversation over a PM to prevent trolling Link to comment https://forums.phpfreaks.com/topic/248624-remvoing-an-object-from-_session/page/2/#findComment-1277131 Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 8, 2011 Author Share Posted October 8, 2011 ... Also tried this: foreach ($_SESSION['cart']['content'] as $key=>$product && $key=>$size) { if ($product['id'] == $id && $product['size'] == $size) { $item_found = $key; ... and this: foreach ($_SESSION['cart']['content'] as $key=>$product & $key=>$size) { if ($product['id'] == $id & $product['size'] == $size) { $item_found = $key; ... and this: foreach ($_SESSION['cart']['content'] as $key=>$product || $size) { if ($product['id'] == $id || $size) { $item_found = $key; ... but fail. Link to comment https://forums.phpfreaks.com/topic/248624-remvoing-an-object-from-_session/page/2/#findComment-1277132 Share on other sites More sharing options...
ManiacDan Posted October 8, 2011 Share Posted October 8, 2011 1) None of those are proper syntax. use a regular foreach loop and print_r the row inside the loop so you know what you're dealing with. 2) Don't feed the trolls. AK would have left you alone if you had ignored him. He's a troll. If someone honestly has nothing better to do than be a dick on the internet, let them be a dick somewhere else. Link to comment https://forums.phpfreaks.com/topic/248624-remvoing-an-object-from-_session/page/2/#findComment-1277197 Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 8, 2011 Author Share Posted October 8, 2011 Thanks ManiacDan for the code suggestion and advice. I've changed the entire code flow to how my cart should work, and have another problem at the moment. I am 100% confident I will know how to remove a session entity with this new code flow, so I think this thread has been concluded. Thanks to everyone who constructively contributed to this thread. !Lock! Link to comment https://forums.phpfreaks.com/topic/248624-remvoing-an-object-from-_session/page/2/#findComment-1277226 Share on other sites More sharing options...
AyKay47 Posted October 9, 2011 Share Posted October 9, 2011 1) None of those are proper syntax. use a regular foreach loop and print_r the row inside the loop so you know what you're dealing with. 2) Don't feed the trolls. AK would have left you alone if you had ignored him. He's a troll. If someone honestly has nothing better to do than be a dick on the internet, let them be a dick somewhere else. wouldn't calling someone a troll on the internet when you know nothing about them also be considered "dick like" behavior.. hmmm i was a dick because I can't stand complete morons on here. Link to comment https://forums.phpfreaks.com/topic/248624-remvoing-an-object-from-_session/page/2/#findComment-1277361 Share on other sites More sharing options...
KevinM1 Posted October 9, 2011 Share Posted October 9, 2011 Since the OP feels the topic has run its course, and because no one can act like an adult, this thread is closed. Link to comment https://forums.phpfreaks.com/topic/248624-remvoing-an-object-from-_session/page/2/#findComment-1277478 Share on other sites More sharing options...
Recommended Posts