Location: PHPKode > projects > MyOWNSpace > MyOWNspace_v8.2/www/classes/example.php
<html>
<head><title>- Guestbook</title></head>
<style>
BODY {font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px}
A:link, A:active, A:visited {color:#0000FF; text-decoration:none}
A:hover {color:#CCCCCC; text-decoration:underline}
</style>
<body>
<?
$db_using = "FLAT"; // choose FLAT DB
// $db_using = "SQL"; // choose SQL DB

if ($db_using == "FLAT") {
	$fields_array = array("author", "comment", "date");
	$db_info = "./guestbook.flatdb.xml";
}
elseif ($db_using == "SQL") {
	/* I've already created a table for my guestbook like this structure:
		----------------------------------------------
		CREATE TABLE `gb` (
			`id` int(3) unsigned NOT NULL default '0',
			`author` varchar(50) NOT NULL default '',
			`comment` text NOT NULL,
			`date` varchar(10) NOT NULL default '',
			PRIMARY KEY  (`id`)
		) TYPE=MyISAM;
		----------------------------------------------
	*/

	$fields_array = array("id", "author", "comment", "date");
	
	$db_host = "localhost";
	$db_user = "root";
	$db_pass = "root";
	$db_name = "jshadow";
	$guestbook_table = "gb";
	$db_info = array($db_host, $db_user, $db_pass, $db_name, $guestbook_table);
}
else
	die();


set_magic_quotes_runtime(0);

require("./guestbook.class.php");

$gb = new Guestbook($fields_array);
$gb->gbConfig($db_info);

if ($_GET['act'] == "sign") { // sign guestbook
	if ($_POST['go']) {
		$date = time();
		$data_array = array($_POST['author'], $_POST['comment'], $date);
		$gb->putIntoDB($data_array);
	}
}
elseif ($_GET['act'] == "delete") { // delete a record
	include "./example_delete.php";
}
elseif ($_GET['act'] == "edit") { // edit a record
	include "./example_edit.php";
}

// show records
$records_total = $gb->getRecordsTotal();
if ( $records_total > 0 ) {
	$records = $gb->getRecords("date");
	foreach ($records as $k => $row) {
		printf("<p><b>ID:</b> %s<br>", $row['id']);
		printf("<b>Author:</b> %s<br>", $row['author']);
		printf("<b>Date:</b> %s<br>", date("d/m/Y - H:i:s", $row['date']));
		printf("<b>Comment:</b><br> %s</p>", nl2br($row['comment']));
		echo "<a href='" . $PHP_SELF . "?act=edit&id=" . $row['id'] . "'>Edit</a> - <a href='" . $PHP_SELF . "?act=delete&id=" . $row['id'] . "'>Delete</a>";
		echo "<hr size='1' color='#999999'>";
	}
}
else {
	echo "<h3>Not any comment yet.</h3>";
}
?>
<hr size="1" color="#FF0000">
<b>Sign this guestbook</b>
<form method="post" action="<?=$PHP_SELF . '?act=sign' ?>">
Name:<br>
<input type="text" name="author" size="25"><br>
Comment:<br>
<textarea name="comment" cols="25" rows="6"></textarea><br>
<input type="submit" name="go" value="Sign">
</form>
</body>
</html>
Return current item: MyOWNSpace