Jump to content

makamo66

Members
  • Content Count

    52
  • Joined

  • Last visited

Community Reputation

0 Neutral

About makamo66

  • Rank
    Regular Member
  • Birthday 10/23/1966

Contact Methods

  • Website URL
    http://www.maureenmoore.com

Profile Information

  • Gender
    Female
  1. Thank you for your helpful input. I implemented the code that you provided and used $_SESSION["cart_items"] instead of $cart_items and now it works!
  2. The var_dump of the $cart_items array is supposed to show an array of $cart_items with the quantities added together for the same id but it doesn't even show an array, it just shows one value. session_start(); $cart_items = $_SESSION["cart_items"]; if ( $cart_items == null ) { $cart_items = array(); } if ( isset($_REQUEST["element_id"]) ) { $id = $_REQUEST["element_id"]; } if ( isset($_REQUEST["quantity"]) ) { $quantity = $_REQUEST["quantity"]; } if ( isset($id) && isset($quantity) ) { if (isset($cart_items[$id])) { $cart_items[$id] += $quantity; } else { $cart_items[$id] = $quantity; } } var_dump($cart_items);
  3. ThanX ginerjm. Your code worked perfectly (except that the dollar signs needed to be escaped)
  4. <table border='1'><tr><th>Remove&nbsp;&nbsp;&nbsp;</th><th width='100'>Your Product&nbsp;&nbsp;</th><th>Quantity</th><th>Description</th><th>Price per item</th><th>Sub Total</th></tr> <?php echo "<form method='post' name='yourForm'>"; echo "<tr><td></td>"; echo "<td><img src=" . $thumbnail . "/></td>"; echo "<td>" . $cart_product_quantity . "</td>"; echo "<td> " . $product . "(s)&nbsp;&nbsp;</td>"; echo "<td> \$" . $price . "</td><td> \$" . $number . "</td></tr>"; echo "</form>"; echo "</table>";
  5. When I echo out my variable in the php file it works fine but when I put the variable in a table cell it doesn't echo out.
  6. How do I get my session to be unset? My form looks like this: foreach ($joined as $i => $qty){ echo "<form action='' method='get' name='yourForm'>"; echo "<button type='submit' name='remove_" . $i . "' value='remove_" . $i . "' class='deletebtn' >X</button>"; echo "</form>"; } My SESSION is defined like this: for($i=0; $i<=5; $i++){ if (isset($_REQUEST["element_id_$i"]) ) { $_SESSION["element_id_$i"] = $_REQUEST["element_id_$i"]; $id = $_SESSION["element_id_$i"]; array_push($_SESSION["element_id"],$id); } $id = $_SESSION["element_id"]; } and the form submits to: if (isset($_REQUEST["remove_$i"]) ){ unset($_SESSION["quantity[$i]"]); unset($_SESSION["element_id[$i]"]); var_dump($_SESSION["element_id"]); var_dump($_SESSION["quantity"]); echo "Received variable " . $_REQUEST["remove_$i"]; echo 'TARGET INDEX TO BE REMOVED: ' . $_SESSION["element_id[$i]"] . '<br><br>'; } The output is: array(1) { [0]=> string(1) "1" } array(1) { [0]=> string(1) "1" } Received variable remove_1 Notice: Undefined index: element_id[1] in C:\xampp\htdocs\TopView\cart5.php on line 147 TARGET INDEX TO BE REMOVED:
  7. When I do the following, it still doesn't work: <?php for($i=0; $i<=5; $i++){ echo "<form action='' method='get' name='yourForm'>"; echo "<button type='submit' value='remove_" . $i . "' name='delete' class='deletebtn'>X</button>"; echo "</form>"; } for($i=0; $i<=5; $i++){ if (isset($_REQUEST["remove_$i"])){ echo "delete"; echo "Received Value: " . $_REQUEST["remove_$i"]; } } ?>
  8. When I remove exit it still doesn't work.
  9. The file test2.php consists of these simple forms: <?php for($i=0; $i<=5; $i++){ echo "<form action='reset4.php' method='get' name='yourForm'>"; echo "<button type='submit' value='delete' name='remove_" . $i . "' class='deletebtn'>X</button>"; echo "</form>"; } ?> It submits to reset4.php which is this simple code: <?php header("Location: test2.php"); exit; for($i=0; $i<=5; $i++){ if (isset($_REQUEST["remove_$i"])){ echo "Deleted"; }} ?> But it doesn't work. The $_REQUEST doesn't populate the address field and it apparently never gets submitted to reset4.php like it should. This is such a simple program, I can't imagine why it doesn't work.
  10. $id is defined like this: for($i=0; $i<=5; $i++){ if (isset($_REQUEST["element_id_$i"]) ) { $_SESSION["element_id_$i"] = $_REQUEST["element_id_$i"]; $id = $_SESSION["element_id_$i"]; array_push($_SESSION["element_id"],$id); } $id = $_SESSION["element_id"]; } and $quantity is similar.
  11. When I use this: $cart_items[$id] = $quantity; or this: $cart_items = array($id => $quantity); I get the error: Illegal offset type
  12. This is the cart array: $cart = array( "1" => "2", "3" => "4", "5" => "6"); var_dump($cart); array(3) { [1]=> string(1) "2" [3]=> string(1) "4" [5]=> string(1) "6" } This is the cart items array: $cart_items = array(); $cart_items["id"] = $id; $cart_items["quantity"] = $quantity; var_dump($cart_items); array(2) { ["id"]=> array(2) { [0]=> string(1) "1" [1]=> string(1) "1" } ["quantity"]=> array(2) { [0]=> string(1) "1" [1]=> string(1) "1" } } I want the key to be "id" and the value to be "quantity" like it is for the cart array. How do I define my cart_items array using variables?
  13. This is what I'm using and it's not working: foreach($cart_items as $item) { foreach($item["id"] as $key => $val) { foreach($item["quantity"] as $i => $value) { if ($key == $i){ if(empty($item["quantity"])){ $item["quantity"] = $value; } elseif (isset($_REQUEST["quantity_$i"]) ) { $item["quantity"] = $value + $_REQUEST["quantity_$i"]; $value = $item["quantity"]; echo "Same product"; }}}}
  14. The last product in the SESSION array is the product with the non-updated quantity. When I update the quantity, I get the previous product and also the updated product. I have to remove the non-updated product.
×
×
  • 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.