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! |
As businesses grow increasingly dependent upon Web applications to provide services to customers, employees and partners, these complex applications become more difficult to secure. Although traditional security solutions protect Internet infrastructure layers, they do not guard against HTTP and HTML attacks. Many organizations that conduct security testing still deploy applications that allow attackers to manipulate their logic and wreak havoc on their business. To mitigate this risk, development and delivery teams must address Web application security throughout the lifecycle, addressing the many layers detailed in this paper. FREE! Go There Now!
|
|
|
|
This tutorial shows new users of IBM WebSphere Business Monitor Version 6.0.2 how to perform the "Hello World" equivalent for monitoring business process applications. It is intended to help you get familiar with the capabilities of the product. FREE! Go There Now!
|
|
|
|
Rational Build Forge Express Edition is an automation framework that packages the latest enterprise-grade technologies into a reliable, flexible and robust configuration designed and priced specifically for small to midsize businesses. The new Rational Build Forge Express eKit provides you with valuable resources – including a case study, podcast, demo, and articles – to help you increase staff productivity, compress development cycles and deliver better software, fast. FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference on December 11 at 1:00 pm ET to get tips on building your own plugins with Rational Method Composer. Get your questions answered! FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference on December 6 at 1:00 pm ET to participate in an agile application development discussion and get your questions answered on using IBM Rational Method Composer in a distributed environment.Get your questions answered! FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to try the IBM SOA Sandbox for connectivity. The SOA Sandbox for connectivity provides a trial environment with the tooling and components to help you explore how to effectively connect your infrastructure and integrate all of the people, processes and information in your company. Use the hosted sandbox to explore SOA techniques that streamline connecting existing IT assets together, as well as learn how to connect them to new business logic. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to try the IBM SOA Sandbox for process. The SOA Sandbox for process focuses on providing a trial environment with the necessary tooling and components required to gain a better understanding of business processes and how to best improve existing business processes to derive value quickly. FREE! Go There Now!
|
|
|
|
As businesses grow increasingly dependent upon Web applications, these complex entities grow more difficult to secure. Most companies equip their Web sites with firewalls, Secure Sockets Layer (SSL), and network and host security, but the majority of attacks are on applications themselves – and these technologies cannot prevent them. This paper explains what you can do to help protect your organization, and it discusses an approach for improving your organization’s Web application security. 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!
|
|
|
|
The unprecedented scope of a service-oriented architecture (SOA) initiative brings to the forefront a number of management and governance issues that were sidestepped in the past. The key to a successful SOA implementation is managing and governing activities throughout the entire SOA delivery lifecycle by ensuring that services conform to the needs of all of the business’s stakeholders. Learn how service lifecycle management allows the business to ensure that the process by which services are defined, created, tested, deployed, optimized and retired is manageable, repeatable and auditable. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |