Location: PHPKode > projects > ezBook > ezbook/ezbook.php
<TITLE>ezBook: powered by www.thanhhai.com</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">

<H1>Sign My Guestbook</H1>

Your Name: <INPUT TYPE=TEXT NAME="Name"><BR>
Your Email : <INPUT TYPE=TEXT NAME="Email"><BR>
Your Comment:<BR>

    mysql_connect ("localhost","root","") or die ("Cannot connect to the SQL server.");	// Connecting to the database server
    mysql_select_db ("ezBook") or die ("Cannot select database."); 						// Selecting the database
    if ($Name AND $Email AND $Comment) {											// If someone signs in the guestbook, insert the information into the database
        $Query  = "INSERT INTO GuestTable (Name, Email, Date, Comment) "; 
        $Query .= "VALUES ('$Name', '$Email', NULL, '$Comment')"; 
        mysql_query ($Query) or die ("Insert Failed!"); 

    $Query = "SELECT * FROM GuestTable ORDER BY Id DESC";
    $GuestArray = mysql_query ($Query) or die ("Select Failed!"); 
    $Total = mysql_num_rows ($GuestArray); 

    echo ("Total $Total messages posted. "); 
    echo ("<A HREF=\"$PHP_SELF?showall=1\">Show all</A>. ");
    echo ("<A HREF=\"$PHP_SELF?showall=0\">Show last 5</A>.");					// If you want to change the number of last messages to be displayed, change the line 38 accordingly

    if ($showall == 0) {
        $Query .= " LIMIT 5";
        $GuestArray = mysql_query ($Query) or die ("Select Failed!"); 

    while ($Guest = mysql_fetch_array ($GuestArray)) { 								// Dump out information in each message
        echo ("<P><TABLE BORDER=1 WIDTH=600>");
        echo ("<TR><TD bgcolor=#CDD5CD VALIGN=TOP WIDTH=200>");
        echo ("Name: " . $Guest['Name'] . "<BR>");
	  echo ("Email: " . $Guest['Email'] . "<BR>");

        $DateStamp = $Guest['Date']; 
        $Year = substr ($DateStamp, 0, 4); 
        $Month = substr ($DateStamp, 4, 2); 
        $Day = substr ($DateStamp, 6, 2); 
	  echo ("Date: $Day/$Month/$Year</TD>"); 										// You may want to chage the date format as you like

	  echo ("<TD VALIGN=TOP>" . nl2br ($Guest['Comment']) . "</TD>"); 
	  echo ("</TR></TABLE>"); 
Return current item: ezBook