I'm trying to make a simple form query a simple db to pull out area codes and display them.
it's been about a year and half since I've had to code php full time and I guess I've forgotten a lot, that and a lot of the pgsql and php commands have changed in that time.
in psuedo code I'm trying to do this
if (!areacode){
print the form;
}else{
run the sql search and display the results
}
I have it so it displays the form, and currently when I do a search it errors out and displays:
Warning: pg_query() [function.pg-query]: Query failed: ERROR: pg_atoi: zero-length string . in /var/www/html/pg_test.php on line 29
Warning: pg_num_rows(): supplied argument is not a valid PostgreSQL result resource in /var/www/html/pg_test.php on line 30
Rows:
The current state of my code is as follows (watch out for odd experimental tweaks)
##################
PHP CODE
##################
<?
$connect = pg_connect("host=localhost dbname=dncl user=admin");
?>
<HTML>
<BODY>
<?
echo $areacode;
if (!$_POST['areacode']){
echo "you didn't enter anything<br>";
print " <form action='pg_test.php' method='post'>
<input type='text' name=areacode value='$_POST['areacode']'>
<input type='submit' value='tryit'>
";
}else{
$sql = "Select * from phonenumbers where areacode = '$_POST['areacode']';";
$results = pg_query($connect, $sql);
$rows = pg_num_rows($results);
echo "Rows:$rows<br>";
for ($i = 0; $i < $rows; $i++){
echo pg_fetch_result($results,$i,0);
echo "<br>";
}
}
pg_close($connect);
?>
</form>
</body>
</html>