/* PHP Guestbook 1.1 Written by Tony Awtrey Anthony Awtrey Consulting See http://www.awtrey.com/support/dbeweb/ for more information 1.1.ora - Mar. 29, 2000 - Version for Oracle by Kari Pannila kartsa@_NO_SPAM_ougf.fi 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 NUMBER (4) NOT NULL, GUEST_NAME VARCHAR2 (50), GUEST_EMAIL VARCHAR2 (50), GUEST_TIME DATE, GUEST_MESSAGE VARCHAR2 (2000), PRIMARY KEY ( GUEST_ID ) ) ; CREATE SEQUENCE GUEST_ID_SEQ START WITH 0 INCREMENT BY 1 MINVALUE 0 NOCACHE NOCYCLE ; */ //////////////////////////////// // 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(guest_id_seq.nextval,'$name','$email',SYSDATE,'$message')"; //////////////////////////////// // This is where we connect first time to the database //////////////////////////////// $c1 = ocilogon("scott","tiger","dbougf"); $stmt = ociparse($c1,$query); OCIexecute($stmt,OCI_DEFAULT); OCIFreeStatement($stmt); OCICommit; } else { //////////////////////////////// // If they didn't include all the required fields set a variable // and keep going. //////////////////////////////// $notall = 1; } } ?>
Please answer all fields
} ?>echo $numguest[0]; ?> people have left me a message.
//////////////////////////////// // This is where we decide to get all the entries or just the last 20. // This variable is set by just adding a '?complete=1' after the URL. //////////////////////////////// $c1 = OCIlogon("scott","tiger","dbougf"); if ($complete == 1) { $query = "SELECT guest_name,guest_email,to_char(guest_time,'DD.MM.YYYY HH24:MI:SS'),guest_message FROM guests ORDER BY guest_time DESC"; } else { echo "Here are the first 20:| Name: echo $guest[0]; ?> | Email: echo $guest[1]; ?> | Time: echo $guest[2]; ?> |
| echo $guest[3]; ?> | ||