title: getting MySQL ID from URL to display information on page
body: <p>I have a products page where 8 product images are in a list which is being populated by images stored in a MySQL database. The images all have associated ID's in which a price, product name, and description is also associated with the same ID. </p>
  
  <p>The idea behind what I am trying to do is; When a user clicks on one of the 8 product images, they will be redirected to a "checkout" page which will display the same image, plus all the information that is also stored under that ID in the database. </p>
  
  <p>As of right now, I have the checkout page URL including the ID of the image (url.com/checkout.php?id=1) and I was hoping to find a way to get all the information stored under that ID in the URL to be displayed where called on the page. </p>
  
  <p>Here is my php code that displays the images in the list on the products page:</p>
  
  <pre><code>    // Grab the data from our template table 
              $sql = "select * from templates"; 
              $result = mysql_query($sql) or die ("Could not access DB: " . mysql_error()); 
              while ($row = mysql_fetch_assoc($result)) 
              { 
                  echo "&lt;li&gt;"; 
                  echo "&lt;a class=\"caption\" href=\"purchase.php?id=\"" . $row['id'] . "&gt;"; 
                  // Note that we are building our src string using the ID from the database 
                  echo "&lt;img src=\"http://URL-REMOVED.com/file_display.php?id=" . $row['id'] . "\" /&gt;"; 
                  echo "&lt;span&gt;"; 
                  echo "&lt;big&gt;" . $row['name'] . "&lt;/big&gt;"; 
                  echo $row['description']; 
                  echo "&lt;/span&gt;"; 
                  echo "&lt;/a&gt;"; 
                  echo "&lt;/li&gt;"; 
  
              }  
  </code></pre>
  
  <p>Here is the php code that is supposed to gather the information of the clicked product (but doesn't):</p>
  
  <pre><code>    if (isset($_GET['id'])) 
          $id=$_GET['id']; 
      else 
           $id=1; 
  
      if (isset($_GET['action'])) 
          $action=$_GET['action']; 
       else 
          $action="empty"; 
  
  
      switch($action){ 
  
          case "add": 
  
          if($_SESSION['cart'][$id]) 
             $_SESSION['cart'][$id]++; 
          else 
              $_SESSION['cart'][$id]=1; 
  
           break;     
  
          case "remove": 
  
          if($_SESSION['cart'][$id]) 
         { 
             $_SESSION['cart'][$id]--; 
  
             if($_SESSION['cart'][$id]==0) 
      unset($_SESSION['cart'][$id]); 
             } 
  
            break;     
  
            case "empty": 
           unset($_SESSION['cart']); 
  
           break;     
           } 
  
   //Display Cart 
  
        if(isset($_SESSION['cart'])) { 
  
              $total=0; 
              foreach($_SESSION['cart'] as $id =&gt; $x) { 
              $result=mysql_query("select image,name,price,description from templates WHERE id=$id"); 
              $myrow=mysql_fetch_array($result); 
              $image=$myrow['image']; 
              $name=$myrow['name']; 
              $price=$myrow['price']; 
              $description=$myrow['description']; 
  
        }  
      }
  </code></pre>
  
  <p>And here is the actual HTML/PHP where the information is supposed to be displayed:</p>
  
  <pre><code>  &lt;a class="caption" href="checkout.php"&gt; 
              &lt;img src="http://URL-REMOVED.com/file_display.php?id=&lt;?php $myrow['id'] ?&gt;"/&gt; 
              &lt;span&gt; 
                  &lt;big&gt; 
                      &lt;strong&gt;&lt;?php $myrow['name'] ?&gt;&lt;/strong&gt; 
                  &lt;/big&gt; 
  
                  &lt;div class="price"&gt;&lt;?php $myrow['price'] ?&gt;&lt;/div&gt; 
              &lt;/span&gt; 
          &lt;/a&gt; 
      &lt;/div&gt; 
      &lt;div id="info_form_container"&gt; 
      &lt;div class="product_info"&gt; 
          &lt;div class="control-group"&gt; 
              &lt;strong&gt;Template Name:&lt;/strong&gt;  
              &lt;?php $myrow['name'] ?&gt; 
          &lt;/div&gt; 
  
          &lt;div class="control-group"&gt; 
              &lt;strong&gt;Template Description:&lt;/strong&gt; 
              &lt;?php $myrow['description'] ?&gt; 
          &lt;/div&gt; 
  
          &lt;div class="control-group"&gt; 
              &lt;strong&gt;Template Price: &lt;/strong&gt; 
              &lt;?php $myrow['price'] ?&gt; 
          &lt;/div&gt; 
      &lt;/div&gt;
  </code></pre>
  
  <p>I guess I'm not really sure if this is even the best method to take? But I definitely want to have the images stored in the database and I definitely want to call them using the ID... </p>
  
  <p>How can I achieve this? Where am I wrong in my code?</p>