Forum Moderators: coopster

Message Too Old, No Replies

Error: Warning: pg_close(): 2 is not a valid PostgreSQL

Error: Warning: pg_close(): 2 is not a valid PostgreSQL

         

Imy_S3

3:48 pm on Mar 2, 2004 (gmt 0)

10+ Year Member



Hi

Have some code below.

Keep getting follwing error:
Warning: pg_close(): 2 is not a valid PostgreSQL link resource in /home/students/ug/ug75ixc/public_html/amenity/amenity.php on line 130

Even though everything works fine keep getting above error.

anyone know why this is?

thanks in advance

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<head>
<title>Shopping</title>
</head>

<body>

<p>Please select the type of amenity you are looking for</p>

<?

$showForm=true;
if (isset($_POST['submit2']))
{

//Connection to Database
$dbcon=pg_connect("host=db port=5477 dbname=c user=i password=t");

//SQL statement looking for information in the database
$sql="SELECT * FROM amenity WHERE amenitytype = '$_POST[option]'";

//Prints the SQL statement
echo $sql;

//Stores the result of the SQL statement
$result = pg_exec($sql);

//Returns the number of rows in the result
$nrows = pg_numrows($result);

if($nrows!= 0)
{
$showForm=false;

print "<p>Your search for " . $_POST[option] . " has the following results </p>";
print "<table border=20>
<tr>
<th>Name
<th>Address Line One
<th>Address Line Two
<th>County
<th>Postcode
<th>Telephone Number
<th>Fax Number
<th>Email
<th>Web Site\n";

for($j=0; $j<$nrows; $j++)
{

$row = pg_fetch_array ($result);

printf ("<tr><td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
</tr>", $myrow['entertainmentname'], $myrow['entertainmentaddresslineone'], $myrow['entertainmentaddresslinetwo'], $myrow['entertainmentcounty'], $myrow['entertainmentpostcode'], $myrow['entertainmenttelephone'], $myrow['entertainmentfax'], $myrow['entertainmentemail'], $myrow['entertainmentwebsite']);

print "<tr><td>" . $row["entertainmentname"];
print "<td>" . $row["entertainmentaddresslineone"];
print "<td>" . $row["entertainmentaddresslinetwo"];
print "<td>" . $row["entertainmentcounty"];
print "<td>" . $row["entertainmentpostcode"];
print "<td>" . $row["entertainmenttelephone"];
print "<td>" . $row["entertainmentfax"];
print "<td>" . $row["entertainmentemail"];
print "<td>" . $row["entertainmentwebsite"];
print "\n";
}
print "</table>\n";
}

else
{
print "<p>No Entry for " . $_POST[option]. "Please select another";
pg_close($dbcon);
$showForm=true;
}

}
if($showForm)
{

echo ( '<form action="amenity.php" method="post">' );

echo "<input type =radio name=option checked value='police'>";
echo ( 'Police <br>' );

echo "<input type =radio name=option value='bowling'>";
echo ( 'Bowling<br>' );

echo "<input type =radio name=option value='casino'>";
echo ( 'Casino<br>' );

echo "<input type= radio name=option value='bookmakers'>";
echo ( 'Bookmakers<br>' );

echo "<input type =radio name=option value='comedy'>";
echo ( 'Comedy Venues <br>' );

echo "<input type =radio name=option value='theatre'>";
echo ( 'Theatre<br>' );

echo "<input type =radio name=option value='museum'>";
echo ( 'Museums<br>' );

echo "<input type =radio name=option value='general'>";
echo ( 'General<br>' );

echo "<input type = submit name= submit2>";
echo ( '<input type = reset value="Clear Form" >' );

echo ( '</form>' );
}

pg_close($dbcon);
?>

</body>
</html>

coopster

4:05 pm on Mar 2, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You have 2 close operations in your script. You are trying to close a connection that is already closed:
<? 
if($nrows!= 0) {
...
} else {
print "<p>No Entry for " . $_POST[option]. "Please select another";
pg_close($dbcon);
$showForm=true;
}
...
if($showForm) {
...
}
pg_close($dbcon);
?>