|
|
|
//this is a very simple guestbook example, i found that tere are not that many
//postgreSQL examples out there for the very beginners, so here is one
//it does not limit number of records per page, it does not give ou administration
//features(for this i have another script - maybe i'll post it here as well later)
//the table is:
/*CREATE TABLE gb_record (
id int4,
name varchar,
email varchar,
location varchar,
comments varchar,
url varchar
)
;
*/
<?
//we do want a proper header for our file, don't we?!
echo "<HTML><HEAD><TITLE>Guestbook Example</TITLE></HEAD><BODY>";
// connect to the database, since each part of this uses
//the connection, we can just connect once at the beginning
$connection=pg_connect("host=yourhos dbname=dbname user=user password=****
port=5432");
if (!$connection)
{
echo "Could not connect to the database";
exit;
}
// if the query string (guestbook.php3?stuff) is add, then present the form to add entries
if ($argv[0] == "add"):
?>
<P>Please take a moment to share your comments with us.</p>
<P>
<FORM NAME="guestbook" ACTION="<?echo $PHP_SELF?>" METHOD=POST>
<INPUT TYPE=hidden NAME=cmd VALUE=send>
Your Name: <INPUT TYPE=text NAME=name>
<BR>Your E-mail address: <INPUT TYPE=text NAME=email>
<BR>Your Web Page address: <INPUT TYPE=text NAME=url>
<BR>Where are you from: <INPUT TYPE=text NAME=location>
<BR>Comments:
<BR><TEXTAREA NAME=comments COLS=60 ROWS=6></TEXTAREA>
<CENTER><INPUT TYPE=submit VALUE=Submit><INPUT TYPE=reset
VALUE=Clear></CENTER>
</FORM>
<?
// if the query string is view, the fetch the guestbook entries
elseif ($argv[0] == "view"):
echo "<H2>View Guestbook Entries</H2>";
$sql='select name, email,url,location, comments from gb_record order by id desc';
// get stuff from the database
// $result = mysql_query( "select name, email, url, job, location, comments
from guestbook");
$result=pg_exec($connection, $sql);
if (!$result)
{
echo "Got no results";
exit;
}
// fetch the rows one at atime, and then echo the data to the page
//we also want to know the number of the records in the database, so that we could
//display the exact number, and it didn't give us a warning: can not get to the next
//record message
$r1 = pg_exec($connection, "select max(id) from gb_record");
$row1 = pg_fetch_row($r1,0);
$num1 = $row1[0];
pg_freeresult(r1);
$r=0;
while ($r<$num1)
{
$row = pg_fetch_array($result,$r);
echo "<HR>";
//we could have these fields in the echo already, but it does not access
// array elements correctly from within ""
$mto=$row[1];
$nam=$row[0];
$urrl=$row[2];
$loc=$row[3];
echo "<p align=justify><BR><B>Message by:</B> <A
HREF=\"mailto:$mto\">$nam</A>";
echo "<BR><B>Web Page:</B> <A HREF=\"$urrl\">$urrl</A>";
echo "<BR><B>From:</B> $loc";
echo "<BR><B>Comments:</B>";
echo "<BR></p>";
echo $row[4];
$r++;
}
echo "<br><H3><A HREF=\"$PHP_SELF?add\">Add an entry to the
guestbook</A></H3>";
pg_freeresult($result);
// if we're submitting a guestbook entry
elseif (isset($cmd) && $cmd == "send"):
// mail guestbook entry to the webmaster
mail ("your@email.here", "guestbook entry", "Comment: $comments\nURL: $url
\nLocation: $location \n", "From: $name <$email>");
// postgreSQL really hates it when you try to put things with ' or "
// characters into a database
$result = pg_exec($connection, "select max(id) from gb_record");
$row = pg_fetch_row($result,0);
$num = $row[0];
$num++;
$comments = addslashes("$comments");
pg_freeresult($result);
//we want to increment the id by 1
pg_exec($connection, "insert into gb_record values
($num,'$name', '$email', '$location', '$comments', '$url');");
// insert the data into the database
?>
<h1>Thank you!</h1><br>We really appreciate your cooperation, to continue
browsing the web-site
<a href="index.html">click here</a>.<br>
<?
else:
// lastly, we must be at the main page. Get the number of entries in the guestbook
//so we can tell the visitor how many there are
$result = pg_exec($connection, "select max(id) from gb_record");
$row = pg_fetch_row($result,0);
$num = $row[0];
if ($num == "")
{
$entry = "There are currently no entries";
}
elseif ($num == "1")
{
$entry = "There is currently 1 entry";
}
else {
$entry = "There are currently $num entries";
}
echo "<h1>Welcome to the <I>Count Zero</I> guestbook.<br> $entry in the
guestbook.</h1>";
echo "<H3><A HREF=\"$PHP_SELF?add\">Add an entry to the
guestbook</A></H3>";
echo "<H3><A HREF=\"$PHP_SELF?view\">View entries in the
guestbook</A></H3>";
endif;
pg_freeresult($result);
pg_close($connection);
?>
</BODY>
</HTML> |
|
| PostGreSQL and MySQL 2 in 1 db Manager Categories : PHP, PHP Classes, Databases, PostgreSQL, MySQL | | | Script for postgresql to walk through the results limiting the results shown per
page. Categories : PostgreSQL, Databases, PHP | | | Monthly and Daily Upcoming Events calendar. Categories : Date Time, PostgreSQL, PHP, Calendar, Databases | | | Logs hits to any page which includes it. Automatically utilises page access information left behind by PHP/FI2.0. Categories : Databases, PHP, mSQL, Databases | | | AUTH (.htaccess style) - a login system that uses PostgreSQL. Categories : PHP, Authentication, Databases, PostgreSQL | | | DBE - Database Expander: Edit PostgreSQL individual database tables online via your Web browser! Categories : PostgreSQL, Complete Programs, Databases, PHP Classes, PHP | | | This program allows you to upload an ODBC ressource - i.e. an MS-Access database to a MySQL server. Categories : Databases, MySQL, Complete Programs, PHP, Databases | | | Save and restore files into postgresql database (PHP SCRIPT) PHP CLASS Categories : PHP, Databases, PostgreSQL, Filesystem | | | Is there any way to test that the $result has null values or not without reading the field values in the results in postgre?
Categories : PostgreSQL, PHP, Databases | | | This is a database wrapper for PostgreSQL, but can be simply modified for any other database type. Categories : Databases, PostgreSQL, PHP | | | Postgresql Database Backup And Restore PHP script Categories : PHP, Databases, PostgreSQL | | | This is a function to display a table for Postgres results. This this code in an include file, require it, and call ShowResults($result) whenever you need to see what your queries result in. Categories : Databases, PHP, PostgreSQL | | | This is Yet Another Sql Abstraction Library. Include it in your script and you can use the most important SQL functions without worrying about the SQL backend. Categories : Databases, PHP, ODBC, MySQL, PostgreSQL | | | Accepts a database & hostname from a user and then HTTP username and password. Uses this to connect to a MySQL database. Produces a form based on the tables it finds there to allow the user to do SELECTs, INSERTs, and DELETEs. Categories : Databases, PHP, MySQL, Complete Programs | | | phpAds, a complete banner and ad management system with detailled tracking and stats. Categories : MySQL, Complete Programs, Ecommerce, PHP, Databases | |
| | | | Peter Tatischev wrote :330
Just to give the courtesy to the persn who wrote the
original script for th mySQL server... I dont` really
remember your name, and i cant seem to find the
script here again, but it was here.....
| |
|
|
|