title: Updating table row while looping through an associative array
body: <p>Trying to carry out two SQL queries within the same table (named Product) while iterating through an associative array, the first SQL query is to get Quantity field from the table (Product), to do some calculation, and the second SQL query is to update the Quantity with its new calculated value.</p>
  <pre><code>   foreach($productQuantities as $product =&gt; $quantity){
  
         $newQnt = 0; 
    
          $stm = $db-&gt;connect()-&gt;prepare(&quot;SELECT quantity FROM product WHERE name=:product&quot;);
          $stm-&gt;bindValue(':product', $product);
          $stm-&gt;execute();
  
         $row = $stm-&gt;fetch();
  
          $newQnt = $row['quantity'] - $quantity;  // HERE IS THE PROBLEM
        
           
                  $stm2 = $db-&gt;connect()-&gt;prepare(&quot;UPDATE product SET quantity=:quantity 
                  WHERE name=:product&quot;);
                  $stm2-&gt;bindValue(':product', $product);
                  $stm2-&gt;bindValue(':quantity', $newQnt);
                  $stm2-&gt;execute(); 
  
   } 
  </code></pre>
  <p>The  $row['quantity'] is always null and gives me the error : Warning: Trying to access array offset on value of type bool.</p>