title: Updating quantity in a data table
body: <p>I am trying to setup an order form where a customer enters any quantity and consequently my inventory gets updated thus keeping current amounts for the next customer, I've been trying to come up with the right code but no luck so far. Any advice will be greatly appreciated, here is my code:</p>
  
  <pre><code>&lt;?php
  session_start(); //Lets start a session! This is the index page
  $_SESSION["access"] = "My_session";
  //We need a header right, well here it is?
  define ("TITLE", "Products page");
  include('templates/header.html');
  ?&gt;
  &lt;h2 class="intro"&gt;
      Looking for the perfect widget for the perfect person? Browse through our small but original
      list of products to purchase. Alternatively you can contact us through our contact page and one of our team will get
      back to you as soon as possible.
      WIDGET ORDER FORM Widget Quantity Cost Dehydrated water " /&gt; $ 18.50 Glass Stems " /&gt; $ 28.50
  
      &lt;?php
      // Get the values from the $_POST array:
      $quantityarray = ((isset($_POST['f_wa']) ? $_POST['f_wa'] : '') || (isset($_POST['f_gl']) ? $_POST['f_gl'] : ''));
  
      include 'connection.php';
  
      # Define the SQL statement
      $query = 'Select ProductID, InStock from Inventory ORDER BY ProductID';
      if ($result = mysql_query($query)) {
          while ($row = mysql_fetch_array($result)) {
              $currentnum = $row['InStock'] - $quantityarray[$row['ProductID']];
              $prodid = $row['ProductID'];
              // execute a SQL statement to update the InStock number
              $query = "UPDATE Inventory SET InStock = $currentnum WHERE ProductID=$prodid";
              sendquery($query);
          }
      }
  
      function sendquery($query)
      {
          if (@mysql_query($query)) {
              print '&lt;p&gt;Table populated.&lt;/p&gt;';
          } else {
              print '&lt;p style="color:red;"&gt;Error executing SQL statement: &lt;br/&gt;' . mysql_error() . '.&lt;/p&gt;
  
      &lt;p&gt;The statement being run was: ' . $query . '&lt;/p&gt;';
          }
      }
  
      ?&gt;
      &lt;?php
      //To conclude we also need the footer, don't we?.
      include('templates/footer.html');
      ?&gt;  
  </code></pre>