title: PHP MySQL Shopping Cart not updating in database
body: <p>I am trying to let the user update quantities in the textfields on the page, then update existing items in their cart in the database with the new values of the textfields on the page.</p>
  
  <p>The quantities are not being updated, but no errors are being generated either.</p>
  
  <p>I can't see any problems with my code, and I'm just at a complete loss as to what could be causing this to not work.</p>
  
  <p>Code:</p>
  
  <pre><code>&lt;?php
  
  
       // If post is not null, then add selected data to corresponding sessionid in database.
  if($_SESSION['last_access'] != null &amp;&amp; $_REQUEST["product"] != null)
  {
     // Sanitize information.
     $info = new SimpleSanitize('post', 'both');
  
     $product = $info-&gt;get('product');
     $quantity = $info-&gt;get('qty');
     $price = $info-&gt;get('price');
  foreach($_POST['items'] as $p=&gt;$q)
  {
   $connection =
          mysql_connect("my01.tadah.com","blah","passsword");
  
   if($connection)
   {
    mysql_select_db("mysql_9269_dbase", $connection);
  
    mysql_query(
            "UPDATE mysql_9269_dbase.sessions SET qty='".$q."' WHERE product='".$p."'")
                 or die(mysql_error());
    // Assume items added successfully.
    $ItemAddedMessage = "Quantities changed.";
  
    // Close connection to database.
    mysql_close($connection);
   }
   else
   $ItemAddedMessage = null;
  }}
  
  ?&gt;
  &lt;?php
  
  //Include SimpleSanitize.
  include 'simplesanitize.php';
  
  // First attempt at PHP Sessions. Wish me luck.
  $ItemAddedMessage = "Adjust your quantities, then click Purchase.";
  // Start the session.
  session_start();
  
  if( !isset($_SESSION['last_access']) || (time() - $_SESSION['last_access']) &gt; 71200 )
   $_SESSION['last_access'] = time();
  
  
  
  // Open the DB connection and select the DB - creates the function getCreativePagerLyte()
  include('configurations.php');
  
  // Gets the data
  $id=isset($_POST['id']) ? $_POST['id'] : '';
  $search=isset($_POST['search']) ? $_POST['search'] : '';
  $multiple_search=isset($_POST['multiple_search']) ? $_POST['multiple_search'] : array();
  $items_per_page=isset($_POST['items_per_page']) ? $_POST['items_per_page'] : '';
  $sort=isset($_POST['sort']) ? $_POST['sort'] : '';
  $page=isset($_POST['page']) ? $_POST['page'] : 1;
  $extra_cols=isset($_POST['extra_cols']) ? $_POST['extra_cols'] : array();
  
  // Uses the creativeTable to build the table
  include('creativeTable.php');
  
  $ct=new CreativeTable();
  
  // Data Gathering
  $params['sql_query']           = 'SELECT product, qty, price FROM sessions WHERE sessionid = "'.session_id().'"'; // IMPORTANT: you must specify the fields and not use *
  $params['search']              = $search;
  $params['multiple_search']     = $multiple_search;
  $params['items_per_page']      = $items_per_page;
  $params['sort']                = $sort;
  $params['page']                = $page;
  
  // Layout Configurations (Most used - the commented lines are the default values)
  $params['header']                 = 'Product, Quantity, Price'; // If you need to use the comma use &amp;#44; instead of ,
  $params['width']                = ',,';
  //$params['search_init']           = true;
  //$params['search_html']          = '&lt;span id="#ID#_search_value"&gt;Search...&lt;/span&gt;&lt;a id="#ID#_advanced_search" href="javascript: ctShowAdvancedSearch(\'#ID#\');" title="Advanced Search"&gt;&lt;img src="images/advanced_search.png" /&gt;&lt;/a&gt;&lt;div id="#ID#_loader"&gt;&lt;/div&gt;';
  //$params['multiple_search_init']  = 'hide';
  $params['items_per_page_init']  = '5000'; // default: '10*$i';
  //$params['items_per_page_all']    = '#TOTAL_ITEMS#';
  //$params['sort_init']              = true;
  //$params['sort_order']              = 'adt';
  //$params['ajax_url']              = $_SERVER['PHP_SELF'];
  
  $ct-&gt;table($params);
  //$product_id = $ct-&gt;data[$key][0];
  
  foreach($ct-&gt;data as $key =&gt; $value){
     $ct-&gt;data[$key][0]='&lt;p name="product"&gt;'.$ct-&gt;data[$key][0].'&lt;/p&gt;';
     $ct-&gt;data[$key][1]='&lt;input id="quantity" name="items[' . $ct-&gt;data[$key][1] . ']" type="text" value="'.$ct-&gt;data[$key][1].'" style="background:#FFFFFF url(qty.png) no-repeat 4px 4px;
                          padding:4px 4px 4px 30px;
                          border:1px solid #CCCCCC;
                          width:220px;
                          height:18px;" /&gt;';
     $ct-&gt;data[$key][2]='&lt;p name="price"&gt;'.$ct-&gt;data[$key][2].'&lt;/p&gt;';
  }
  
  // If its an ajax call
  if($_POST['ajax_option']!=''){
  
    if(strpos($_POST['ajax_option'],'items_per_page')!==false)
      $out_ajax['items_per_page']=utf8_encode($ct-&gt;draw_items_per_page());
  
    if(strpos($_POST['ajax_option'],'body')!==false)
      $out_ajax['body']=utf8_encode($ct-&gt;draw_body());
  
    if(strpos($_POST['ajax_option'],'pager')!==false)
      $out_ajax['pager']=utf8_encode(getCreativePagerLite($page,$ct-&gt;total_items,$ct-&gt;items_per_page));
  
    echo json_encode($out_ajax);
    exit;
  
  }else{
  
    // Insert a Pager into the table (I used this CreativePager Lite version because its very easy to use, but you may use any pager system that you like)
    $ct-&gt;pager = getCreativePagerLite($page,$ct-&gt;total_items,$ct-&gt;items_per_page);
  
    $out = '&lt;form name="ct_form" action="checkout.php" method="post"&gt;' . $out;
    $out=$ct-&gt;display();
  
  }
  
  ?&gt;
  
  &lt;!DOCTYPE xhtml PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"&gt;
  &lt;head&gt;
  
  
  
    &lt;link rel="stylesheet" type="text/css" href="css/style.css"&gt;
    &lt;link rel="stylesheet" type="text/css" href="css/creative.css"&gt;
  
  &lt;title&gt;Mild Steel Products | One Stop Fasteners&lt;/title&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
  &lt;link href="style.css" rel="stylesheet" type="text/css" /&gt;
  &lt;script type="text/javascript" src="js/jquery.js" &gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="js/jquery.tools.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="js/cufon.js"&gt;&lt;/script&gt;
  &lt;script src="js/Kozuka_Gothic.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;!-- Fix for Internet Explorer 9 Beta --&gt;
  &lt;!--[if gte IE 9]&gt;
  &lt;script type="text/javascript"&gt;
  Cufon.set('engine', 'canvas');
  &lt;/script&gt;
  &lt;![endif]--&gt;
  &lt;script type="text/javascript" charset="utf-8"&gt;
  // &lt;![CDATA[
  $(document).ready(function(){
  Cufon.replace('h1,h2,h3',  {    
  });
  
          $(function() { 
                       $("h3.message").delay(3000).fadeOut(); 
          });
  
  });
  // ]]&gt;
  &lt;/script&gt;
  &lt;script type="text/javascript" src="js/jquery-1.4.2.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="js/creative_table.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="js/creative_table_ajax.min.js"&gt;&lt;/script&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  &lt;script language="javascript" type="text/javascript"&gt;
          function submit() {
                   document.getElementById('ct_form').submit();
                   }
  &lt;/script&gt;
  &lt;div class="main"&gt;
   &lt;div class="header"&gt;
       &lt;div class="logo"&gt;&lt;a href="index.php"&gt;&lt;img src="images/logo.png" border="0" alt="logo" /&gt;&lt;/a&gt;&lt;/div&gt;
        &lt;div class="menu"&gt;
          &lt;ul&gt;
  &lt;li&gt;&lt;a href="index.php"&gt;Home&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="products.php"&gt;Order Online&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="products.php" class="active"&gt;Products&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="about.php"&gt;About us&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="contact.php"&gt;Contact us&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
        &lt;/div&gt;
        &lt;div class="clr"&gt;&lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="header_text2"&gt;
        &lt;h2&gt; Checkout&lt;/h2&gt;
        &lt;p&gt;Adjust your quantities, then click purchase. &lt;/p&gt;
        &lt;div class="clr"&gt;&lt;/div&gt;
      &lt;/div&gt;
    &lt;div class="clr"&gt;&lt;/div&gt;
      &lt;div class="top_sup_resize"&gt;
      &lt;div class="menu2"&gt;
          &lt;ul&gt;
            &lt;!--&lt;li&gt;&lt;a href="mildsteel_allthread.php" style="font-size:x-small; color:white;"&gt;Allthread&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href="mildsteel_hexnuts.php" style="font-size:x-small; color:white;"&gt;Hex Nuts&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href="mildsteel_washers.php" style="font-size:x-small; color:white;"&gt;Washers&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href="mildsteel_hnbkss.php" style="font-size:x-small; color:white;"&gt;Hex Bolt &amp;amp; Nut Kits, Setscrews&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href="mildsteel_screws.php" style="font-size:x-small; color:white;"&gt;Screws&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href="mildsteel_last.php" style="font-size:x-small; color:white;"&gt;Cup Head Bolts &amp;amp; Nuts&lt;/a&gt;&lt;/li&gt;--&gt;
          &lt;/ul&gt;
        &lt;/div&gt;
        &lt;div class="clr"&gt;&lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="clr"&gt;&lt;/div&gt;
    &lt;div class="body"&gt;
     &lt;div class="body_left"&gt;
     &lt;h2&gt;&lt;?php echo '&lt;a href="javascript:submit();"&gt;Purchase&lt;/a&gt;'; ?&gt;&lt;/form&gt;&lt;/h2&gt;
     &lt;h3 class="message"&gt;&lt;?php echo $ItemAddedMessage . $_REQUEST["quantity"]; ?&gt;&lt;/h3&gt;
     &lt;p&gt;&lt;/p&gt;
     &lt;div id="container"&gt;
    &lt;?php echo $out;?&gt;
  &lt;/div&gt;
  
     &lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/div&gt;
       &lt;div class="clr"&gt;&lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="footer"&gt;
    &lt;div class="footer_resize"&gt;
      &lt;ul&gt;
        &lt;li&gt;&lt;a href="index.php"&gt;home&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="products.php"&gt;order online&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="products.php"&gt;products&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="about.php"&gt;about&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="contact.php"&gt;contact&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;
      &lt;p&gt;Copyright © 2010, &lt;a href="http://www.onestopfasteners.com.au/"&gt;One Stop Fasteners&amp;reg;&lt;/a&gt;. All Rights Reserved&lt;/p&gt;
      &lt;div class="clr"&gt;&lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Can someone please tell me what I am doing wrong?</p>
  
  <p>Any help at all is much appreciated.</p>
  
  <p>Thanks!</p>