title: Warning: pg_query(): Query failed: ERROR: syntax error at or near
body: <p>I have a script that is supposed to display the results of a Postgres query based on a link that the user clicks on a previous page.</p>
  
  <p>For example, when the user clicks on the Title of a project, it directs them to a page that shows them more attributes about the project, which are contained in columns in the database.</p>
  
  <p>I already have the page working where users can click on a Title, but once they click a title, my second page to display the other attributes of the project is not working.</p>
  
  <pre><code>&lt;?php
  
  ini_set('display_errors',1);  error_reporting(E_ALL);
  
  $row = false;
  
  if (isset($_GET['pid']) &amp;&amp; filter_var($_GET['pid'], FILTER_VALIDATE_INT, array('min_range' =&gt; 1)) ) { 
  
      $pid = $_GET['pid'];
  
      require('/var/www/postgres_connect.php');
      $q = 'SELECT * FROM public.' + "tblProjects" + 'WHERE ' + "tblProjects" + '.ProjectID = ' + "$pid";
      $r = pg_query ($dbconn, $q);
      if (pg_num_rows($r) == 1) {
  
          $row = pg_fetch_assoc ($r);
  
          $page_title = $row['ProjectID'];
  
          echo "&lt;div align=\"center\"&gt;
          &lt;b&gt;{$row['ProjectID']}&lt;/b&gt; by
          {$row['ProjectTitle']}&lt;br /&gt;";
  
          echo '&lt;p align="center"&gt;' . ((is_null($row['totalcost'])) ? '(No Cost Recorded)' :
          $row['totalcost']) . '&lt;/p&gt;';
  
      }   
      pg_close($dbconn);
  }
  
  if (!$row) {
      $page_title = 'Error';
      echo '&lt;div align="center"&gt;This page encountered an error!&lt;/div&gt;';
      }
  
  
  ?&gt;
  </code></pre>
  
  <p>Running this script produces the following error:</p>
  
  <blockquote>
    <p>Warning: pg_query(): Query failed: ERROR: syntax error at or near "20131418" LINE 1: 20131418 ^ in /var/www/html/view_project.php on line 13</p>
    
    <p>Warning: pg_num_rows() expects parameter 1 to be resource, boolean given in /var/www/html/view_project.php on line 14</p>
  </blockquote>
  
  <p>Now, I don't think the second error is a problem because solving the first error will produce a result of the query and then clear up the second error.</p>
  
  <p>I don't understand what is wrong with the syntax; having <code>$pid</code> at the end of the query returns an integer(20131418) which is being called out as invalid syntax.  What can I do to solve this issue?</p>