title: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in PHP?
body: <p>I promise, this will be the last question today. But I got an error 'Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/a1014025/public_html/practice/cart/cart.php on line 58' with this code:</p>
  
  <pre><code>&lt;?php
  include('connect.php');
  session_start();
  ?&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Cart&lt;/title&gt;
      &lt;link rel='stylesheet' href='css/main.css' /&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;?php
      $page = 'index.php';
  
      if(isset($_GET['add'])){
          $add_id = $_GET['add'];
          $quantity = mysql_query("SELECT id, quantity FROM products WHERE id='$add_id'");
          while($quantity_row = mysql_fetch_assoc($quantity)){
              if($quantity_row['quantity'] !=@$_SESSION['cart_'.$add_id]){
                  @$_SESSION['cart_'.$_GET['add']]+='1';
                  header('Location: index.php');
              }
              else{
                  header('Location: index.php?err=max');
              }
          }
  
      }
  
      if(isset($_GET['remove'])){
          $_SESSION['cart_'.(int)$_GET['remove']]--;
          header("Location: index.php");
      }
  
      if(isset($_GET['delete'])){
          $_SESSION['cart_'.(int)$_GET['delete']]='0';
          header('Location: index.php');
      }
  
      function products(){
          $get = mysql_query("SELECT id, name, description, price FROM products WHERE quantity &gt; 0 ORDER BY id DESC");
          if(mysql_num_rows($get) == 0){
              echo "There are no products to display.";
          }
          else{
              while($get_row = mysql_fetch_assoc($get)){
                  echo '&lt;p&gt;'.$get_row['name'].'&lt;br /&gt;'.$get_row['description'].'&lt;br /&gt;$'.$get_row['price'].' &lt;a href="cart.php?add='.$get_row['id'].'"&gt;Add&lt;/a&gt;&lt;/p&gt;';
              }
          }
      }
  
      function paypal_items(){
          $num = 0;
          foreach($_SESSION as $name =&gt; $value){
              if($value!=0){
                  if(substr($name, 0, 5) == 'cart_'){
                      $id = substr($name, 5, strlen($name)-5);
                      $get = mysql_query("SELECT id, name, price, shipping, shipping2 FROM products WHERE id=".$id);
                      while($get_row = mysql_fetch_assoc($get)){
                          $num++;
                          echo '&lt;input type="hidden" name="item_number_'.$num.'" value="'.$id.'"&gt;';
                          echo '&lt;input type="hidden" name="item_name_'.$num.'" value="'.$get_row['name'].'"&gt;';
                          echo '&lt;input type="hidden" name="amount_'.$num.'" value="'.$get_row['price'].'"&gt;';
                          echo '&lt;input type="hidden" name="shipping_'.$num.'" value="'.$get_row['shipping'].'"&gt;';
                          echo '&lt;input type="hidden" name="shipping2_'.$num.'" value="'.$get_row['shipping2'].'"&gt;';
                          echo '&lt;input type="hidden" name="quantity_'.$num.'" value="'.$value.'"&gt;';
  
                      }
                  }
              }
          }
      }
  
      function cart(){
          $total = 0;
          foreach($_SESSION as $name =&gt; $value){
              if($value&gt;0){
                  if(substr($name, 0, 5)=='cart_'){
                      $id = substr($name, 5, strlen($name)-5);
                      $get = mysql_query("SELECT id, name, price FROM products WHERE id='$id'");
                      while($get_row = mysql_fetch_assoc($get)){
                          $sub = $get_row['price']*$value;
                          echo $get_row['name'].' x '.$value.' @ $'.number_format($get_row['price'], 2).' = $'.$sub.' &lt;a href="cart.php?add='.$id.'"&gt;[+]&lt;/a&gt; &lt;a href="cart.php?remove='.$id.'"&gt;[-]&lt;/a&gt; &lt;a href="cart.php?delete='.$id.'"&gt;[Delete]&lt;/a&gt;&lt;br /&gt;';
                      }
                  }
                  $total += $sub; 
              }
          }
          if($total==0){
              echo "You cart is empty.";
          }
          else{
              echo "&lt;p&gt;Checkout with PayPal for your $".$total." total.&lt;/p&gt;";
              ?&gt;
              &lt;form action="https://www.paypal.com/cgi-bin/webscr" method="post"&gt;
              &lt;input type="hidden" name="cmd" value="_cart"&gt;
              &lt;input type="hidden" name="upload" value="1"&gt;
              &lt;input type="hidden" name="business" value="ddromano@comcast.net"&gt;
              &lt;?php paypal_items(); ?&gt;
              &lt;input type="hidden" name="currency_code" value="USD"&gt;
              &lt;input type="hidden" name="amount" value="&lt;?php echo $total; ?&gt;"&gt;
              &lt;input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but03.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"&gt;
              &lt;/form&gt;
              &lt;?php
  
          }
      }
  
      ?&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p></p>