I'm creating a form that will include two drop down lists. I have decided to separate the code for the drop down lists from the rest of the form since I will probably need those drop down lists again in another form. When I keep the code in the main code, everything works. I get a list of all the records I'm looking for. But when I separate the list and make a function call to the drop down list, I get this error:
Warning: Supplied argument is not a valid PostgreSQL link resource in
/var/www/nngov/include/class_list.box on line 9
Here's my class_list.box file:
<?
require ($DOCUMENT_ROOT.'/nngov/include/database.inc');
function buildClassListBox()
{
$sql = "SELECT class_id, position_code, title FROM classification ORDER BY title";
$result = pg_exec($conn, $sql);
if (!$result)
exit;
?>
<tr>
<td width=25% class="form">Classification:</td>
<td width=75% class="form">
<select name='class_id'>
<?
if ($result)
{
for($i = 0; $row = @pg_fetch_array($result,$i); $i++) {
$class_id = $row['class_id'];
$position_code = $row['position_code'];
$title = $row['title'];
echo "<option value=$class_id>$title - $position_code</option>\n";
}
echo "</select></td></tr>";
}
}
Here's how I call it from addjob.php:
<?
include ($DOCUMENT_ROOT.'/nngov/include/class_list.box');
buildClassListBox();
?>
Here's my database.inc file:
<?php
//
// database.inc
//
// Database Information
$dbname = "personnel";
$dbuser = "jeff";
$conn = pg_connect("dbname=$dbname user=$dbuser");
if (!$conn) {
echo "Could not connect to database.";
exit;
}
?>
I'm sure I probably need to be returning a variable but I'm not sure what.