Php postgres
From DreamsteepWiki
KL POSTGIS PHP LIB php_postgis
<html>
<head>
<style type="text/css">
body {
font-family: arial, verdana, sans-serif;
font-size: 12px;
}
a { text-decoration: none; }
#search_table {
width: 700px;
padding: 3px;
font-weight: bold;
background-color: #FFCC33;
margin: 0 auto 0 auto;
border: 1px solid #000000;
text-align: center;
}
#insert_table {
width: 700px;
padding: 3px;
font-weight: bold;
background-color: #ECD672;
margin: 0 auto 0 auto;
border: 1px solid #000000;
text-align: center;
}
#results_table {
width: 700px;
padding: 3px;
font-weight: bold;
background-color: #bbbbbb;
margin: 0 auto 0 auto;
border: 1px solid #FFCC33;
text-align: center;
}
#results_table_td {
border: 1px solid #FFCC33;
padding: 3px;
background-color: #FFCC33;
font-size: 11px;
}
input { margin-bottom: 0; border: 1px solid #000; }
</style>
<script type="text/javascript">
function disp_confirm()
{
var r=confirm("Are you sure?")
if (r==true) { return true; }
else { return false; }
}
</script>
</head>
<body>
<form name="search" method="GET" action="index.php">
<table id="search_table">
<tr>
<td>
<h3 style="margin: 0;">POSTGRES DATABASE INTERACTION</h3>
Keith Legg December 2009
</td>
</tr><tr>
<td>
tablename to search : <input type="text" name="sertab" size="10" />
<input type="hidden" name="order" value="Grantee" />
</td>
</tr><tr>
<td>
<input type="submit" name="Submit" value="Search" />
</td>
</tr><tr>
<td colspan="4" style="text-align: center; font-size: 10px;">
<a href="upload.php">dont click me</a><br />
</td>
</tr>
</table>
<table id="insert_table">
<tr>
<td>
INSERT A RECORD :
tablename <span class="plainlinks">[http://how2gainweightfast.org <span style="color:black;font-weight:normal;text-decoration:none!important;background:none!important; text-decoration:none;">weight gain</span>]</span> to insert to : <input type="text" name="insertt" size="10" />
</td>
</tr><tr>
<td>
<input type="submit" name="insert" value="Insert" />
</td>
</table>
</form>
<?php
$host = '127.0.0.1';
$username = 'postgres';
$password = 'password';
$db = 'bentonpg';
if ( (isset($_GET['sertab'])) ) {
$dbconn = pg_connect("host=$host dbname=$db user=$username password=$password")
or die('Could not connect: ' . pg_last_error());
$sertab= trim(stripslashes($_GET['sertab']));
$order= trim(stripslashes($_GET['order']));
if ((strlen($sertab) > 1) ) {
$query= ("SELECT * FROM " . $sertab );
}
$search_db= pg_query($query);
$results= pg_num_rows($search_db);
if ($results < 1) {
echo '<div style="text-align: center; width: 100%; font-weight: bold;">No Records Found</div>';
} else {
//THE QUERY STRING
echo '<table border="1">' ;
echo '<tr>' ;
echo '<td id="results_table">' ;
print $query;
echo '</td>' ;
echo '</tr>' ;
//THE RESULTS
while ($row = pg_fetch_array($search_db)) {
echo '<tr>' ;
echo '<td id="results_table_td">' ;
echo $row[1];
echo '</td>' ;
echo '</tr>' ;
}
echo '</table>';
}
pg_close($dbconn);
} else {}
?>
</body>
</html>

