title: PostgreSQL syntax error at or near FROM
body: <p>I'm having a problem with this piece of PHP. It's meant to print out a table of products chosen from the last page - passed through POST with names in the format 'quantityN' where N is a number &lt;150 &amp; refers to a unique ID - primary key - in the table CSGames.</p>
  
  <p>I know that the problem isn't with my $connection, as I successfully load the list in the last page.</p>
  
  <p>The error:</p>
  
  <pre><code>Warning: pg_query() [function.pg-query]: Query failed: ERROR: syntax error at or near "FROM" LINE 1: ...efnumber,name,platform,price WHERE refnumber='20' FROM CSGam... ^ in /berw/homes1/g/gij2/public_html/cs25010/basket.php on line 102
  </code></pre>
  
  <p>My live project can be found <a href="http://users.aber.ac.uk/gij2/cs25010/" rel="nofollow">here</a> - index>catalogue>basket.</p>
  
  <p>Does anyone have any idea what's wrong with my code? Thanks in advance.</p>
  
  <pre><code>echo "
  &lt;table border='1'&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  Title
              &lt;/td&gt;
              &lt;td&gt;
                  Platform
              &lt;/td&gt;
              &lt;td&gt;                                            
                  Price
              &lt;/td&gt;
              &lt;td&gt;
                  Quantity
              &lt;/td&gt;
              &lt;td&gt;
                  Total price
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      ";
  
  $id=0;
  $sum=0;
  while($id&lt;150){ //  Loops through the POST associative array
      if($_POST['quantity'.$id]&gt;0){
          $result=pg_fetch_row(pg_query($connection,"SELECT refnumber,name,platform,price WHERE refnumber='".$id."' FROM CSGames"));
          $total=$result[4]*$_POST['quantity'.$id];
          echo "
              &lt;tr&gt;
                  &lt;td&gt;
                      ".$result[1]."
                  &lt;/td&gt;
                  &lt;td&gt;
                      ".$result[2]."
                  &lt;/td&gt;
                  &lt;td&gt;
                      &amp;pound;".$result[3]."
                  &lt;/td&gt;
                  &lt;td&gt;
                      ".$_POST['quantity'.$id]."
                  &lt;/td&gt;
                  &lt;td&gt;
                      &amp;pound;".$total."
                  &lt;/td&gt;
              &lt;/tr&gt;
              ";
          $sum+=$total;
      }
      $id++;
  }
  </code></pre>