Page 1 of 1

Store the result of a SQL query to a PHP variable

Posted: Sat Jan 24, 2004 4:22 am
by conjokes
<br></bog>
</center><br><br><hr>

<?PHP
$conn = pg_Connect ("port=5432 dbname=jack
user=ma103tw");
if (!$conn) {
exit;
}
$result1 = pg_exec ($conn, "select MAX(offender_no) from offenders;");/*this will yield a one figure result*/

$result2 = pg_exec ($conn, "select * from civil_fines where offender = $result;");/*tried to compare offender to the above query result result1, this does not work, i get the error message below:*/

Warning: pg_exec() query failed: ERROR: parser: parse error at or near "id" in public_html/project/enterFine2.php on line 12

if (!$result1) {exit;}

if (!$result2) {exit;}

echo "<b>The client $client has beem added to the database<ol>";

pg_Close($conn);
echo "</ul></b><hr>";
?>

<small><i>

</i></small>
</body></html>

please can anyone help, thanks

Posted: Sat Jan 24, 2004 5:40 pm
by Jade
Lol, well for one thing you aren't comparing the right variable in the $result2 query.

This code:
$result2 = pg_exec ($conn, "select * from civil_fines where offender = $result;");/*tried to compare offender to the above query result result1, this does not work, i get the error message below:*/

Should be:

$result2 = pg_exec ($conn, "select * from civil_fines where offender = $result1;");/*tried to compare offender to the above query result result1, this does not work, i get the error message below:*/

Notice how i changed $result to $result1 -- let me know if that doesn't solve the problem.

Jade