Note that there are some explanatory texts on larger screens.

plurals
  1. POhow can i remove the item from the cart
    primarykey
    data
    text
    <p>I tried the code below to delete the item from the cart but in the item is not deleted. The index_to_remove is the index of the values in a multidimensional array. When I click on remove the item does not delete. The session is also started but still no success please help me out with this. </p> <pre><code>&lt;?php ///////////////////////////////////////////////////////// //section 3 if user wants to remove an item from cart/// //////////////////////////////////////////////////////// if(isset($_POST['index_to_remove'])&amp;&amp;$_POST['index_to_remove']!="") { $key_to_remove=$_POST['index_to_remove']; echo 'index-'.$key_to_remove.':Count-'; if(count($_SESSION["cart_array"])&lt;=1) { unset($_SESSION["cart_array"]); } else { unset($_SESSION["cart_array"][$key_to_remove]); sort($_SESSION["cart_array"]); echo count($_SESSION["cart_array"]); } } ?&gt; &lt;?php ////////////////////////////////////////// // section 4 render the cart for user view ///////////////////////////////////////// $cartOutput=""; $cartTotal=""; if(!isset($_SESSION['cart_array'])||count($_SESSION['cart_array'])&lt;1) { $cartOutput="&lt;h2 align='center'&gt;Your shopping catr is empty &lt;/h2&gt;"; } else { $i=0; foreach($_SESSION['cart_array'] as $each_item) { $item_id=$each_item['item_id']; $sql=mysql_query("SELECT * FROM product WHERE id='$item_id' LIMIT 1"); while($row=mysql_fetch_array($sql)) { $product_name=$row['product_name']; $price=$row['price']; $details=$row['details']; } $totalprice=$price*$each_item['quantity']; $cartOutput.='item details: '.$details.'&lt;br&gt;'; $cartOutput.='item Quantity: '.$each_item['quantity'].'&lt;br&gt;'; $cartOutput.='item Price:$'.$price.'&lt;br&gt;'; $cartOutput.='totalprice:$'.$totalprice.'&lt;br&gt;'; $cartOutput.=''.$i.'&lt;form action="cart.php" nethod="post"&gt; &lt;input name="deleteBtn'.$item_id.'" type="submit" value="remove"/&gt; &lt;input name="index_to_remove" type="hidden" value="'.$i.'"/&gt; &lt;/form&gt;'; $i++; } } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload