Hi All
First post. PHP/PostgreSQL newbie...
I'm trying to create a simple web page with a dropdown menu. The values for the dropdown menu are retrieved from a database table. The code I've got is...
<html>
<body>
<select>
<?php
$db = pg_connect("host=hostname port=5432 dbname=dbname user=user password=password") or die ("Could not connect to DB");
$sql = pg_query(sprintf("SELECT hostname FROM pkgchk"));
while ($row = pg_fetch_assoc($sql))
{
echo "<option value=$row[hostname]>$row[hostname]</option>";
}
pg_close($db);
?>
</select>
</body>
</html>
I've racked my brain and done a lot of googling, and I can't understand what's wrong.
I suspect the DB connection is not working. However, if I execute the file from the command line, I get...
[root@svr-app-nagios html]# php -f file.html
<html>
<body>
<select>
<option value=test>test</option> </select>
</body>
</html>
...which looks OK (there's only 1 record so far in the DB, test), so I presume the DB connection is OK?
Many thanks in advance
Stephen