Note that there are some explanatory texts on larger screens.

plurals
  1. POAmount not increasing or decreasing
    text
    copied!<p>I have a<code>PHP</code> CODE that looks like the one below. The idea is for users to be able to enter an amount and when the click on <code>update</code> the item will update. But the problem is, that my code is not working.</p> <p><strong>php</strong></p> <pre><code>&lt;?php session_start() ?&gt; &lt;?php if(isset($_POST['pid']) &amp;&amp; isset($_POST['length']) &amp;&amp; isset($_POST['Qty']) &amp;&amp; isset($_POST['Category'])){ $pid = $_POST['pid']; $length = $_POST["length"]; $qty = $_POST['Qty']; $Category = $_POST['Category']; **They are more codes below in this PHP tag which just check if the item the user is adding is already in the basket and if not it should add it.** } ?&gt; </code></pre> <p><strong>Adjust the Quantity of an item <em>(this is the code I am having the problem with)</em></strong></p> <pre><code> &lt;?php if (isset($_POST['item_to_adjust']) &amp;&amp; $_POST['item_to_adjust'] != "") { // execute some code $item_to_adjust = $_POST['item_to_adjust']; $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; } foreach ($_SESSION["cart_array"] as $array_key=&gt;$each_item) { if ($each_item['item_id'] == $item_to_adjust &amp;&amp; $each_item['length'] == $length &amp;&amp; $each_item['Category'] == $Category) { $_SESSION["cart_array"][$array_key]['quantity']+=$quantity; } } } ?&gt; </code></pre> <p><em><strong>HTML</em></strong></p> <pre><code>&lt;form action="check.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="item_to_adjust" type="hidden" value="' . $item_id . '" /&gt; &lt;/form&gt; </code></pre> <p><strong>I HAVE TRY</strong></p> <p>I have <code>echo</code> out the <code>$quantity</code> to see if the amount I have entered as pass though and It has. So I know that part of the code is working.</p> <p><strong>Issue</strong> I think it something to do with my <code>foreach</code> statement but I can't find it. I have try everything I know but I can't find anything.</p> <p>Please help me.</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