Note that there are some explanatory texts on larger screens.

plurals
  1. POUndefined index in deleting $_SESSION
    text
    copied!<p>I have this code to delete any idea from a cart... I need to delete two<code>$_SESSION</code>. 1) <strong>$_SESSION["cart_array"]</strong></p> <p>2 <strong>$_SESSION["minicart"]</strong></p> <p>Without me adding <code>$_SESSION["minicart"]</code> it does delete the <code>$_SESSION["cart_array"]</code> but when i added it i got the <code>minicart</code> part i got an <code>undefined index: minicart</code>. So I </p> <p><strong>tried</strong></p> <p><strong>if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) &amp;&amp; !isset($_SESSION["minicart"]) || count($_SESSION["minicart"]) &lt; 1) {</strong></p> <p><em>the code above checks // If the cart session variable is not set or cart array is empty</em>*</p> <p>to the <em>orginal</em> <strong>if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) &lt; 1) {</strong></p> <p>So </p> <pre><code>&lt;?php // if user wants to remove an item from cart if (isset($_POST['index_to_remove']) &amp;&amp; $_POST['index_to_remove'] != "") { // Access the array and run code to remove that array index $key_to_remove = $_POST['index_to_remove']; if (count($_SESSION["cart_array"]["minicart"]) &lt;= 1) { unset($_SESSION["cart_array"]["minicart"]); } else { unset($_SESSION["cart_array"]["minicart"] ["$key_to_remove"]); sort($_SESSION["cart_array"]["minicart"]); } } ?&gt; </code></pre> <p><strong>My quesion</strong> Looking at the <strong>tried</strong> what I am i doing wrong in the <code>if</code> statement and also what am I doing wrong in the <code>statement</code> to delete the <code>($_SESSION["cart_array"]) AND ($_SESSION["minicart"])</code></p> <p>If this is still unclear please leave a comment and I will do my best to explain it again.</p>
 

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