Store the result of a SQL query to a PHP variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
conjokes
Forum Newbie
Posts: 1
Joined: Sat Jan 24, 2004 4:22 am

Store the result of a SQL query to a PHP variable

Post 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
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Post 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
Post Reply