% ls -R .: config/ smartyguest.php templates/ templates_c/ ./templates: smartyguest.tpl ./templates_c: smartyguest.tpl.php
<html><head><title>My Guestbook</title></head>
<body>
<h1>Welcome to my Guestbook</h1>
<h2>Please write me a little note below</h2>
<form action="{$SCRIPT_NAME}" method="POST">
<textarea cols=40 rows=5 name="note" wrap=virtual></textarea>
<input type="submit" value=" Send it ">
</form>
<h2>The entries so far:</h2>
{section name=msgs loop=$notes}
{$notes[msgs].id} {$notes[msgs].ts} {$notes[msgs].comment}<br>
{/section}
</body></html><?php
require('Smarty.class.php');
$smarty = new Smarty;
$smarty->debugging = true;
mysql_connect('localhost','nobody');
mysql_select_db('mydb');
/* insert new note */
if(isset($note)) {
$ts = date("Y-m-d H:i:s");
mysql_query("insert into comments values
(0,'$note','$ts')");
}
/* read existing notes */
$result = mysql_query('select * from comments');
if(!$result) echo mysql_error();
while($notes[]=mysql_fetch_array($result,MYSQL_ASSOC));
$smarty->assign('notes',$notes);
$smarty->display("smartyguest.tpl");
?>