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.
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.
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.
<?php
ini_set('display_errors',1); error_reporting(E_ALL);
$row = false;
if (isset($_GET['pid']) && filter_var($_GET['pid'], FILTER_VALIDATE_INT, array('min_range' => 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 "<div align=\"center\">
<b>{$row['ProjectID']}</b> by
{$row['ProjectTitle']}<br />";
echo '<p align="center">' . ((is_null($row['totalcost'])) ? '(No Cost Recorded)' :
$row['totalcost']) . '</p>';
}
pg_close($dbconn);
}
if (!$row) {
$page_title = 'Error';
echo '<div align="center">This page encountered an error!</div>';
}
?>
Running this script produces the following error:
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
Warning: pg_num_rows() expects parameter 1 to be resource, boolean given in /var/www/html/view_project.php on line 14
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.
I don't understand what is wrong with the syntax; having $pid
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?