/* PHP Guestbook 1.1 1.1 - Oct. 20, 1999 - changed the SQL statement that reads data back out of the database to reverse the order putting the newest entries at the top and limiting the total displayed by default to 20. Added the ability to get the complete list by appending the URL with '?complete=1'. Added the code and additional query to count and list the total number of entries and included a link to the complete list. 1.0 - Initial release This is the SQL statement to create the database required for this application. CREATE TABLE guests ( guest_id int(4) unsigned zerofill DEFAULT '0000' NOT NULL auto_increment, guest_name varchar(50), guest_email varchar(50), guest_time timestamp(14), guest_message text, PRIMARY KEY (guest_id) ); */ //////////////////////////////// // This checks to see if we need to add another guestbook entry. //////////////////////////////// if (($REQUEST_METHOD=='POST')) { //////////////////////////////// // This loop removed "dangerous" characters from the posted data // and puts backslashes in front of characters that might cause // problems in the database. //////////////////////////////// for(reset($HTTP_POST_VARS); $key=key($HTTP_POST_VARS); next($HTTP_POST_VARS)) { $this = addslashes($HTTP_POST_VARS[$key]); $this = strtr($this, ">", " "); $this = strtr($this, "<", " "); $this = strtr($this, "|", " "); $$key = $this; } //////////////////////////////// // This will catch if someone is trying to submit a blank // or incomplete form. //////////////////////////////// if ($name && $email && $message ) { //////////////////////////////// // This is the meat of the query that updates the guests table //////////////////////////////// $query = "INSERT INTO guests "; $query .= "(guest_id, guest_name, "; $query .= "guest_email, guest_time, guest_message) "; $query .= "values(0000,'$name','$email',NULL,'$message')"; mysql_pconnect("host","user","password") or die("Unable to connect to SQL server"); mysql_select_db("dbasename") or die("Unable to select database"); mysql_query($query) or die("Insert Failed!"); } else { //////////////////////////////// // If they didn't include all the required fields set a variable // and keep going. //////////////////////////////// $notall = 1; } } ?>
![]() |
||||||
|
||||||
Home - Why Choose CKD? - Gradings - Events - Contact Us - Guestbook |