Jump to content

rcast

Members
  • Posts

    6
  • Joined

  • Last visited

rcast's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I didn't even know you could use ternary operators and switches with PHP! lmao, thanks sir!
  2. I'm lost... Can somebody show me how to structure my array so I can access and manipulate it correctly.
  3. This is what I wanted, thank you mac_gyver. Can you give me an example? Because I can understand C++ arrays, that's kind of my thing, but PHP is different and I don't have much of a clue how to work with it.
  4. Great this helped me fix that problem. However now say I have added 3 items to cart: List after added 3 items to cart Item 1 - (DELETE) Item 2 Item 3 New list generated after item 1 deleted: Item 1 (array element 1 instead of array element 0, became item 1, throwing off the entire array) Item 2 So basically, following the above example, after I delete item 1 from the cart my array looks like this: $_SESSION['item'][0][0] = EMPTY < -------------- Need to reorder so the two elements below this fill the empty spot $_SESSION['item'][1][0] = Correct $_SESSION['item'][2][0] = Correct I'm guessing I need to resort the array moving each array element's items down one index, within the delete function code - How would I do this?
  5. I've been working on the delete item from cart functionality all day. Still cannot figure this out. When I add 2+ items to my cart, and try to delete any item but the last item added, the script deletes the listing the last item added no matter which one I'm attempting to delete. I could do this in C++ but the php solution is evading me. This has frustrated me today for over 4 hours just this one little problem. Can somebody please shine light on this for me, to help me see why I'm so close to finishing the delete functionality but it won't quite work. Here's my code: header.html (included in cart at top): session_start(); // For personal debugging -- REMOVE WHEN DONE // if ($_GET['des']) { session_destroy(); unset($_GET['des']); } // ---- // // Count Cart Items // if (empty($_SESSION['count_cart'])) { $_SESSION['count_cart'] = 0; } // Handle Delete Item // if ($_POST['submitted']) { $_SESSION['count_cart']--; $delItem = $_POST['delItem']; unset($_SESSION['item'][$delItem]); unset($_POST['submitted']); } // Handle setting sessions // if ($_POST['name'] == $PHPSESSID && isset($_POST['mdl_key'])) { $idx = $_SESSION['count_cart']; $_SESSION['count_cart']++; $_SESSION['item'][$idx][0] = $_POST['mdl_key']; $_SESSION['item'][$idx][1] = $_POST['model']; $_SESSION['item'][$idx][2] = $_POST['manufacturer']; $_SESSION['item'][$idx][3] = $_POST['sellprice']; $_SESSION['uri'][$idx] = $_POST['uri']; } And here is the code for the shoppingcart_customer.php page where the above is included with include: <form name="del" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <?php $i=0; $count = $i + 1; foreach ($_SESSION['item'] as $key=>$v1) { if (isset($_SESSION['item'][$key])) { echo "<tr><td width='30px'></td><td bgcolor='white'>".$count.".) "; foreach ($v1 as $v2){ echo $v2." "; } } echo " - <a href='".$_SESSION['uri'][$i]."' target='_blank'>View Details</a> | <input type='submit' value='Delete' name='delete'/> <input type='hidden' name='delItem' value='".$i."'/> <input type='hidden' name='submitted' value='TRUE'/> </td><td width='80px'></td></tr>"; $i++; } ?> </form> and here is the html $_POST code: <form enctype="multipart/form-data" action="shoppingcart-customer.php" method="post"> <input type="hidden" name="name" value="<?php echo $PHPSESSID; ?>"/> <input type="hidden" name="mdl_key" value="<?php echo $mdl_key; ?>"/> <input type="hidden" name="model" value="<?php echo $model; ?>"/> <input type="hidden" name="manufacturer" value="<?php echo $manufacturer; ?>"/> <input type="hidden" name="sellprice" value="<?php echo $sellprice; ?>"/> <input type="hidden" name="uri" value="<?php echo $_SERVER['REQUEST_URI']; ?>"/> <input type="submit" name="addtocart" value="Add To Cart" id="hyperlink-style-button"/> </form>
×
×
  • 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.