Note that there are some explanatory texts on larger screens.

plurals
  1. POForeach condition issue
    primarykey
    data
    text
    <p>I have the following code below but the problem is that it not working. The code is meant to update a quantity of whatever the users enters.</p> <p>IF I echo <code>$type $size $quantity</code> i can see that the value as been sent.</p> <p><code>foreach ($_SESSION["cart_array"] as $array_key=&gt;$each_item)</code> I think the problem is with this but I can't seem to see it. </p> <p><em><strong>Can someone please take a look and see if they can find the problem please. Thanks</em></strong></p> <p><strong>ISSUES</strong></p> <p>if I enter a number in the form to update. It wouldn't update.</p> <p><strong>PHP</strong></p> <pre><code> &lt;?php session_start(); ?&gt; &lt;?php if (isset($_POST['item_to_adjust']) &amp;&amp; isset($_POST['size']) &amp;&amp; isset($_POST['type'])) { $item_to_adjust = $_POST['item_to_adjust']; $type = $_POST['type']; $size = $_POST['size']; $quantity = $_POST['quantity']; $quantity = preg_replace('#[^0-9]#i', '', $quantity); // filter everything but numbers if ($quantity &gt;= 100) { $quantity = 99; } if ($quantity &lt; 1) { $quantity = 1; } if ($quantity == "") { $quantity = 1; } $i = 0; foreach ($_SESSION["cart_array"] as $array_key=&gt;$each_item) { $i++; if ($each_item['item_id'] == $item_to_adjust &amp;&amp; $each_item['size'] == $size &amp;&amp; $each_item['type'] == $type) { $_SESSION["cart_array"][$array_key]['quantity']+=$quantity; } } } ?&gt; </code></pre> <p><strong>HTML</strong></p> <pre><code>&lt;form action="cart.php" method="post"&gt; &lt;input name="quantity" type="text" value="' . $each_item['quantity'] . '" size="1" maxlength="2" /&gt; &lt;input name="adjustBtn' . $item_id . '" type="submit" value="Update" /&gt; &lt;input name="size" type="hidden" value="' . $each_item['length'] . '" /&gt; &lt;input name="type" type="hidden" value="' . $each_item['Category'] . '" /&gt; &lt;input name="item_to_adjust" type="hidden" value="' . $item_id . '" /&gt; &lt;/form&gt; </code></pre>
    singulars
    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