This is a guestbook script, that stores all records in a MYSQL database. Displays records by pages. Highly configurable interface. For more information contact me at: nerd@kic.kmtn.ru See demo of the script at: http://php.inc.ru
By : lyonchik
<?
/********************************************************************************
Guestbook by lyonchik: nerd@kic.kmtn.ru
Contact me to report bugs, give your comments or
to develop your own personalized Web applications.
This is a simple guestbook. It consists only of one file.
All you need to do is create a MYSQL database table and set the variables below
to conform to your settings and that's it.
The sample query to create a table should be:
"CREATE TABLE guestbook (id int(5) NOT NULL auto_increment, name varchar(20),
email varchar(20), message text, date datetime, PRIMARY KEY (id))"
And the guestbook is ready to go. Enjoy!
You can freely distribute this code. For any suggestions and comments write to:
'nerd@kic.kmtn.ru'. Feel free to email me URLs where this guestbook works,
I would love to hear that my work is appreciated.
*********************************************************************************/
// Define MYSQL server information
$server = 'localhost'; // MYSQL server;
$user = ''; // User to connect to MYSQL server;
$password = ''; // Password;
$database = 'database name'; // The name of the database;
$table = 'guestbook'; // The name of your database table;
// Define page layout variables
$guestbook_name = "My guestbook page"; // Guestbook page name;
$titlecolor = 'black'; // Title font color;
$tablewidth = "90%"; // Table width in pixels or percentage;
$bgcolor = '#AAAAAA'; // Table background color value (name of hex equivalent);
$bordercolor = '#000000'; // Table border color value (name of hex equivalent);
$bordersize = 5; // Table border size;
$cellspacing = 0; // Table cellspacing value;
$cellpadding = 5; // Table cellpadding value;
$messagecellcolor = '#BBAAAA'; // message cell color;
$namecolor = '#0000EE'; // name font color;
$messagecolor = '#000099'; // message font color;
$mainfont = '#000033'; // main text font color;
$maxshow = 10; // Number of messages to display per page;
?>
<HTML>
<META http-equiv=Content-Type content="text/html; charset=windows-1251">
<HEAD>
<TITLE>
<?
echo $guestbook_name;
?>
</TITLE>
<script language="javascript">
function checkForm()
{
if ((document.forms.myGB.name.value == '') || (document.forms.myGB.message.value == ''))
{
alert('Fill in required fields!');
}
else {
document.forms.myGB.submit();
}
}
</script>
</HEAD>
<?
echo "<BODY bgcolor=" . $bgcolor . ">";
echo "<div align=center><h1><font color=" . $titlecolor . ">" . $guestbook_name . "</font></h1>";
if (isset($message))
{
if ($email == "")
{
$email = "no_email";
}
mysql_connect ($server, $user, $password) or die ("Can't connect!");
mysql_select_db ($database) or die ("Can't open database!");
$sql = "INSERT INTO $table (name, email, message, date) VALUES ('$name', '$email', '$message', NOW())";
$result = mysql_db_query($database, $sql);
if ($result)
echo "<meta http-equiv='Refresh' content='0; URL=" . $PHP_SELF . "'>";
else
echo "Error! Check the form!";
mysql_close();
}
if (!isset($show))
{
$show = 0;
}
mysql_connect($server, $user, $password) or die ("Can't connect!");
mysql_select_db($database) or die ("Can't open database!");
$sql = "SELECT * FROM $table ORDER BY id DESC";
$result = mysql_db_query($database, $sql);
if ($result)
{
$count = mysql_num_rows($result);
$sqlshow = "SELECT * FROM $table ORDER BY id DESC LIMIT $show, $maxshow";
$result = mysql_db_query($database, $sqlshow);
?>
<table width=<? echo $tablewidth ?> cellspacing=<? echo $cellspacing ?> cellpadding=<? echo $cellpadding ?> border=<? echo $bordersize ?> bordercolor=<? echo $bordercolor ?>>
<?
while (($myrow = mysql_fetch_array($result)))
{
echo "<tr><td colspan=2 valign=top bgcolor=" . $messagecellcolor . "><font color=" . $messagecolor . ">Sent by <b>" . htmlspecialchars($myrow["name"]) . "</b><i>, " . $myrow["date"] . "</i><br>Email: <a href=mailto:" . htmlspecialchars($myrow["email"]) . ">" . htmlspecialchars($myrow["email"]) . "</a><br><br>" . htmlspecialchars($myrow["message"]) . "</font></td></tr>";
}
?>
</table>
<?
}
else
echo "Error!";
mysql_close();
echo "<font color=" . $mainfont . ">";
echo "<br>";
$pages = $count / $maxshow;
if ($pages < 1)
{
$pages = 1;
}
if ($pages / (int) $pages <> 1)
{
$pages = (int) $pages + 1;
}
else
{
$pages = $pages;
}
$pagenow = ($show/$maxshow + 1);
echo "Page " . $pagenow . " of " . $pages . "<br>";
$next = $show + $maxshow;
$previous = $show - $maxshow;
if ($pages <> 1)
{
if ($previous < 0)
{
echo "<a href=" . $PHP_SELF . "?show=" . "$next" . ">";
echo "<acronym title='Next " . $maxshow . " records'>>>></acronym></a> ||";
}
elseif ($next >= $count)
{
echo "<a href=" . $PHP_SELF . "?show=" . "$previous" . ">";
echo "<acronym title='Previous " . $maxshow . " records'><<<</acronym></a> ||";
}
else
{
echo "<a href=" . $PHP_SELF . "?show=" . "$previous" . ">";
echo "<acronym title='Previous " . $maxshow . " records'><<<</acronym></a>";
echo " | ";
echo "<a href=" . $PHP_SELF . "?show=" . "$next" . ">";
echo "<acronym title='Next " . $maxshow . " records'>>>></acronym></a> ||";
}
}
echo " Pages: ";
$i = 0;
while ($i < $pages)
{
$ri = $i + 1;
$showpage = $i * $maxshow;
echo "<a href=" . $PHP_SELF . "?show=" . $showpage . ">" . $ri . "</a> ";
$i++;
}
?>
<p>
(*) Required fields
<form name='myGB' action=<? echo $PHP_SELF ?> method='post'>
* Name:<br><input type='text' name='name' maxlength=20><br>
Email:<br><input type='text' name='email' maxlength=20><br>
* Message:<br><textarea name='message' rows=5 cols=30></textarea><br>
<a href="javascript:checkForm()">Send</a>
</form>
</font>
</div>
</BODY>
</HTML>
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More Content Management Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
This whitepaper presents the benefits of successfully introducing static analysis into your organization using IBM Rational Software Analyzer. Additionally, it identifies some common pitfalls that can hinder the effective use of static analysis tooling as well as presents 10 simple strategies designed to help you quickly realize the value of static analysis using Rational Software Analyzer. FREE! Go There Now!
|
|
|
|
Learn how you can extend modern application lifecycle management to IBM System z through the IBM Rational Software Delivery Platform (SDP). The Did you say mainframe? e-kit includes podcasts, webcasts, tutorials, white and red papers, demos, and articles designed to help ease the challenges of modernizing your enterprise. This complimentary kit for mainframe developers is a practical, how-to guide for making the most of an existing development environment, including the skills and infrastructure already in place at an established enterprise. FREE! Go There Now!
|
|
|
|
Download a free trial version of IBM Rational Developer for System z, software that can help you deliver core development capabilities; the power of Java Platform, Enterprise Edition (Java EE); and rapid application development support to diverse enterprise application development teams. With comprehensive development tools to help create, deploy and maintain traditional enterprise and composite applications, Rational Developer for System z enables developers with different technical backgrounds to easily participate in important technology projects. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial of the Rational Host Access Transformation Services (HATS) Toolkit. The HATS toolkit provides a set of plug-ins for the IBM Rational Software Delivery Platform to help you easily extend your legacy applications. HATS makes your 3270 and 5250 applications available as HTML through the most popular Web browsers, while converting your host screens to a Web look and feel and it also enables you to develop new Web, portal, and rich-client applications. FREE! Go There Now!
|
|
|
|
Join this webcast to see how IBM Data Studio Developer and pureQuery can take the pain out of Java data access. uApplications developed using both Java and SQL have become a common requirement. Database connectivity using Java Database Connectivity (JDBC) to create an application is a multi-step tedious process, and tooling that covers both SQL and Java has been unavailable, until now. IBM Data Studio introduces the pureQuery platform: a high-performance, Java data access platform focused on simplifying the tasks of developing, managing, and optimizing database applications and services. FREE! Go There Now!
|
|
|
|
Learn how Rational Build Forge can extend a simple compile and package build process by adding customization and deployment capability. Go from a manual method to automating: checking for code changes; getting the latest source; compiling and packaging; customizing; copying to and restarting a deployment server; and sending e-mail notification that a new version is available. FREE! Go There Now!
|
|
|
|
Asset Reuse is a key strategy for companies looking to create innovative solutions to solve complex software development problems. Searching for, identifying, updating, using and deploying software assets can be a difficult challenge. Listen to this webcast, to learn about strategies and tools that you can leverage for a successful project, including Rational Asset Manager, Rational Software Architect and WebSphere Service Registry and Repository. FREE! Go There Now!
|
|
|
|
This whitepaper provides areas to consider when evaluating any software configuration management solution. It addresses how the IBM solutions (Rational ClearCase and Rational ClearQuest) meet the needs and requirements of both project leaders and developers to provide successful Software Change and Configuration Management. FREE! Go There Now!
|
|
|
|
Informix Dynamic Server (IDS) Express Edition offers outstanding online transaction processing (OLTP) database performance, while helping to simplify and automate many of the tasks associated with deploying databases for small business applications. IDS 11 further extends the ease of management and applications integration with the Admin API and Scheduler, high availability with Continuous Log Restore for backup server recovery in case of a primary server failure, and column level encryption to protect personal and company private data. FREE! Go There Now!
|
|
|
|
In this webcast, you'll get an introduction to the eXtreme Transaction Processing (XTP) features of WebSphere Extended Deployment and the common architectural traits required by XTP applications. See how WebSphere Extended Deployment's ObjectGrid feature provides a state-of-the-art infrastructure for hosting XTP applications. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |