capstin Posted December 6, 2007 Share Posted December 6, 2007 Hello fellow php'ers... I am having a little trouble in my design of a shopping cart for a website i am putting together. It has had me baffled for weeks now. Below is the demo link i have been using for testing my components. I basically have an html page splite into 3 sections... One for a search, two for search results and three for my shopping cart. If (when the page loads) i add/remove a song to/from my shopping cart it works fine. But, if i do a new search and add a new song my cart goes way wonky! Have a bash at it using the link below... Any help would be most welcome. It is driving me insane! I just can't work out why executing the same set of code would produce different results. http://www.capstinpole.co.uk/picknclick-demo/nutsnbolts/switch.php (select the bottom option All.hmtl...) - The switch.php page resets my $_SESSION arrays to default. If you need anymore info on this please let me know... A massive selection box in the post for the one who solves the mystery. Please note: I am fairly new to all this programming so no laughing! Best wishes! Michael Link to comment https://forums.phpfreaks.com/topic/80487-solved-php-shopping-cart-giving-me-grief/ Share on other sites More sharing options...
PHP_PhREEEk Posted December 6, 2007 Share Posted December 6, 2007 We can't trouble shoot code by visiting a link... you gotta post the code! I would assume a shopping cart would be a fairly big chunk of code, so try and keep it to what's most likely relevant if you have an idea where the problem lies. PhREEEk Link to comment https://forums.phpfreaks.com/topic/80487-solved-php-shopping-cart-giving-me-grief/#findComment-408069 Share on other sites More sharing options...
capstin Posted December 6, 2007 Author Share Posted December 6, 2007 no probs... cart.php receives the following variables... <form action="cart.php" method="post" name="CartGoodies" target="FooterFrame"> <input name="item_no" type="hidden" value="<? echo $item_no; ?>"> <input name="artist" type="hidden" value="<? echo $artist; ?>"> <input name="song" type="hidden" value="<? echo $song; ?>"> <input name="Submit" type="submit" class="style10" value="Add to cart" /> <input name="manufact" type="hidden" value="<? echo $manufact; ?>"> <input name="cost" type="hidden" value="<? echo $cost; ?>"> </form> ------------------------------------------- cart.php script... <? $_SESSION['total'] = 0.00; // Accumulates Cost $count = $_SESSION['rec_count']; $dup_chk = $_POST['item_no']; // if (!empty($_POST['artist'])) { for ($c = 1; $c < $count; $c++) { if ($_SESSION['item_no'][$c] == $dup_chk) { // checking for duplicate cart entries... $_SESSION['qty'][$c] +=1; $_SESSION['amount_adj'][$c] = (float) $_POST['cost'] * $_SESSION['qty'][$c]; $_SESSION['artist'][$count] = ""; $c = $count; } else { //no duplicates found... Add contents to session var's... $_SESSION['item_no'][$count] = $_POST['item_no']; $_SESSION['artist'][$count] = $_POST['artist']; $_SESSION['song'][$count] = $_POST['song']; $_SESSION['manufact'][$count] = $_POST['manufact']; $_SESSION['qty'][$count] = 1; $_SESSION['amount_adj'][$count] = $_POST['cost']; } } } if ($count == 1){ //Check for first run... * * * * * * * * * * * * * * * * $_SESSION['item_no'][$count] = $_POST['item_no']; $_SESSION['artist'][$count] = $_POST['artist']; $_SESSION['song'][$count] = $_POST['song']; $_SESSION['manufact'][$count] = $_POST['manufact']; $_SESSION['qty'][$count] = 1; $_SESSION['amount_adj'][$count] = $_POST['cost']; } //Remove Item ... $remove is passed through the browser - <a href="cart.php?remove=<? echo $i+1; ?> if (!empty($remove)){ //variable wipeouts unset($_SESSION['item_no'][$remove]); unset($_SESSION['artist'][$remove]); unset($_SESSION['song'][$remove]); unset($_SESSION['manufact'][$remove]); unset($_SESSION['qty'][$remove]); unset($_SESSION['amount_adj'][$remove]); } // Display Cart contents >>> $i=0; while ($i < $count) { If (empty($_SESSION['artist'][$i+1])) { $i++; $msg5 = "Artist $i is empty - statements executed."; } else { // draw html row Hope this helps... Thanks for support! Michael Link to comment https://forums.phpfreaks.com/topic/80487-solved-php-shopping-cart-giving-me-grief/#findComment-408212 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.