aebstract Posted March 31, 2009 Share Posted March 31, 2009 Okay, here is my cart.php where everything happens for updating the cart: <?php header("Cache-control: private"); if(!isset($_SESSION["id"])) { header("Location: index.php?page=login"); exit; } if (isset($_POST['checkout'])){ header("Location: index.php?page=checkout"); exit; } if (isset($_POST['updatecart'])){ foreach ($_SESSION['cart'] as $id2 => $array2){ $count = count($array2); foreach ($array2 as $material2 => $array3){ $count2 = count($array3); foreach ($array3 as $finish2 => $array4){ $postqty = $id2.$material2.$finish2; if ($_POST[$postqty] == 0) { if ($count > 1){ if ($count2 > 1){ unset ($_SESSION['cart'][$id2][$material2][$finish2]); } else { unset ($_SESSION['cart'][$id2][$material2]); } } else { unset ($_SESSION['cart'][$id2]); } } else { if (isset($array4['size'])) { $_SESSION['cart'][$id2][$material2][$finish2] = array(qty => $_POST[$postqty], size => $array4['size']); } else { $_SESSION['cart'][$id2][$material2][$finish2] = array(qty => $_POST[$postqty]); } } } } } } if (isset($_POST['checkout'])){ echo "checkout"; } $showCart = showCart(0); $content .= "<div id=\"full_content\"> Shopping Cart<br /> $showCart </div>"; ?> There is a big functions.php page, I can post if needed (don't think it is). If you guys need to look at any other code just let me know. Here is my problem: When I put in a new number for the item, say I have 2 of item A and change it to 5 of item A and click update. It does this without a problem. It'll loop through and check to see if which items are suppose to be updated and do it as it should be. I have my parts split in to sections, just be a column name in my db. My problem is that ONLY on one category type, when I update ANY part on the cart page, the items from that specific category get completely removed from the cart. No matter what item I try to update.. I am lost as to why this is doing this, I really hope someone can point out what is going wrong. While you guys look at this I'm going to get a sample array for the cart to post to show what it looks like. edit: Here is a sample array: Array ( [48] => Array ( [Aluminum] => Array ( [uncoated] => Array ( [qty] => 4 ) ) ) [33] => Array ( [Aluminum] => Array ( [uncoated] => Array ( [qty] => 7 [size] => 2.2 ) ) ) [11] => Array ( [stainless Steel] => Array ( [uncoated] => Array ( [qty] => 1 [size] => 4.5 ) ) ) ) This is for item id 48,33,11. The one that will get deleted when you update any item is id 11. Quote Link to comment Share on other sites More sharing options...
aebstract Posted March 31, 2009 Author Share Posted March 31, 2009 Okay, I've noticed it does it to 3 categories out of 10 categories of parts. Quote Link to comment Share on other sites More sharing options...
aebstract Posted March 31, 2009 Author Share Posted March 31, 2009 *bump* The only difference I know of between these parts are their category listings, and I don't see how that would have anything to do with this. Quote Link to comment Share on other sites More sharing options...
aebstract Posted March 31, 2009 Author Share Posted March 31, 2009 Hate to continuously bump, but last one for the day before I get off work. (It's almost on page 2) Hopefully get some words in here by tomorrow morning Thanks in advance. Quote Link to comment Share on other sites More sharing options...
aebstract Posted April 1, 2009 Author Share Posted April 1, 2009 *bump* Quote Link to comment Share on other sites More sharing options...
aebstract Posted April 1, 2009 Author Share Posted April 1, 2009 OKAY UPDATE: Here is an update on this issue, I added every part in the database to the cart and then hit the update button. It removed certain items from the display but was still in the array. So it's something in the display of the cart after the update button is hit. Here is where it gets displayed from: function showCart() { global $db; $totalprice = 0; $output = ""; $color1 = "#EEEEEE"; $color2 = "#DDDDDD"; $row_count = 0; if (isset($_SESSION['cart'])) { $output .= '<form action="index.php?page=cart" method="post" id="cartfunctions">'; foreach ($_SESSION['cart'] as $id => $array2){ foreach ($array2 as $material => $array3){ foreach ($array3 as $finish => $array4){ $result = mysql_query("SELECT * FROM p_products WHERE id='$id'") or DIE(mysql_error()); while($r=mysql_fetch_array($result)) { $partnumber=$r["partnumber"]; $partname=$r["partname"]; $description=$r["description"]; $category=$r["category"]; $price=$r["price"]; } $row_color = ($row_count % 2) ? $color1 : $color2; $output .= " <table width=\"590\" style=\"border-top: 1px solid #000; background-color: $row_color;\"> <tr> <td width=\"100\" valign=\"top\"><img src=\"products/$partnumber-cart.jpg\" class=\"jkimagelarge\" title=\"products/$partnumber.jpg\" /></td> <td width=\"350\"> $partname<br /> $partnumber<br /> $$price<br /><br /> Material: $material<br /> Finish: $finish"; if (isset($array4['size'])){ $output .= "<br />Size: {$array4['size']}"; } $output .= "</td> <td width=\"60\"><input type=\"text\" name=\"$id$material$finish\" value=\"{$array4['qty']}\" size=\"3\" maxlength=\"3\" /></td> <td width=\"80\">"; $qty = "{$array4['qty']}"; $qtyprice = $price*$qty; $output .= "$$qtyprice</td> </tr> </table>"; $row_count++; $totalprice = $totalprice + $qtyprice; } } } $output .= "<p align=\"right\">Grand Total: $totalprice</p>"; $output .= "<input type=\"submit\" value=\"\" name=\"updatecart\" id=\"updatecart\" /><br /><br />"; $output .= '</form>'; $output .= "<form action=\"index.php?page=cart\" method=\"post\"><input type=\"submit\" value=\"\" name=\"checkout\" id=\"checkout\" /></form>"; } else { $output .= '<p>You shopping cart is empty.</p>'; } return $output; } Quote Link to comment Share on other sites More sharing options...
aebstract Posted April 1, 2009 Author Share Posted April 1, 2009 Gah, edit button goes away over time. I do believe that they are being deleted now that I have been looking at it harder. I needed to go back to the cart page after updating for it to take affect, which means that I should be able to move my print of the cart down through my code till I find where it's messing it up, I'll post back with details as I figure it out ;( Quote Link to comment Share on other sites More sharing options...
aebstract Posted April 1, 2009 Author Share Posted April 1, 2009 I think my problem is something to do with the space in the array name when trying to update it. If the name of it is "Stainless Steel" it will be removed, if it is "Aluminum" it is okay, same goes with "Mild Steel" gets deleted. Something to do with the space. Quote Link to comment Share on other sites More sharing options...
aebstract Posted April 1, 2009 Author Share Posted April 1, 2009 lol, I changed my item in my database from Stainless Steel to Stainless Steel and it works now. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.