WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : A very simple postgreSQL guestbook script.
Categories : PostgreSQL, Databases, PHP Click here to Update Your Picture
Peter Tatischev
Date : Apr 19th 2000
Grade : 2 of 5 (graded 8 times)
Viewed : 29163
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Peter Tatischev
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

//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>



AUTH (.htaccess style) - a login system that uses PostgreSQL.
Categories : PHP, Authentication, Databases, PostgreSQL
Logs hits to any page which includes it. Automatically utilises page access information left behind by PHP/FI2.0.
Categories : Databases, PHP, mSQL, Databases
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
Script for postgresql to walk through the results limiting the results shown per page.
Categories : PostgreSQL, Databases, PHP
This is a database wrapper for PostgreSQL, but can be simply modified for any other database type.
Categories : Databases, PostgreSQL, PHP
Save and restore files into postgresql database (PHP SCRIPT) PHP CLASS
Categories : PHP, Databases, PostgreSQL, Filesystem
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
Postgresql Database Backup And Restore PHP script
Categories : PHP, Databases, PostgreSQL
Monthly and Daily Upcoming Events calendar.
Categories : Date Time, PostgreSQL, PHP, Calendar, Databases
PostGreSQL and MySQL 2 in 1 db Manager
Categories : PHP, PHP Classes, Databases, PostgreSQL, MySQL
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
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
DBE - Database Expander: Edit PostgreSQL individual database tables online via your Web browser!
Categories : PostgreSQL, Complete Programs, Databases, PHP Classes, PHP
phpYellow Pages Standard
Categories : PHP, Complete Programs, Databases, Directories, Search
Paginator - a class that can help you to split MySQL database query result sets to pages.
Categories : MySQL, Databases, HTML, PHP
 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.....