head 1.1;
access;
symbols;
locks
root:1.1; strict;
comment @# @;
1.1
date 2004.03.09.19.56.23; author root; state Exp;
branches;
next ;
desc
@@
1.1
log
@Initial revision
@
text
@
////////////////////////////////
// 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("www","training","fah2Yoon")
or die("Unable to connect to SQL server");
mysql_select_db("training") 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;
}
}
?>
|
A
Continuing Education Forum for IEC Professionals
|
|
|
Learning
Cafe
Alumni Bulletin Board | Faculty
Bulletin Board
(Scroll down to view posted comments)
if ($notall == 1) { ?>
Please
answer all fields
} ?>
////////////////////////////////
// This is where we connect to the database for reading.
////////////////////////////////
mysql_pconnect("www","training","fah2Yoon")
or die("Unable to connect to SQL server");
mysql_select_db("training") or die("Unable to select database");
////////////////////////////////
// This is where we count the number of entries.
////////////////////////////////
$query = "SELECT COUNT(*) FROM guests";
$numguests = mysql_query($query) or die("Select Failed!");
$numguest = mysql_fetch_array($numguests);
?>
echo $numguest[0]; ?>
people have left 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.
////////////////////////////////
if ($complete == 1) {
$query = "SELECT * FROM guests ORDER BY guest_time DESC";
} else {
$query = "SELECT * FROM guests ORDER BY guest_time DESC LIMIT 20";
}
$guests = mysql_query($query) or die("Select Failed!");
////////////////////////////////
// This will loop as long as there are records waiting to be processed.
// Notice the plain HTML inside the while loop structure. PHP is flexable
// enough to allow you to break into and out of the "code" at any point.
////////////////////////////////
while ($guest = mysql_fetch_array($guests)) {
?>
Name:
echo $guest['guest_name']; ?>
Email:
echo $guest['guest_email']; ?>
////////////////////////////////
// The database has a timestamp record type that we can use to show the
// date the guestbook was filled out.
////////////////////////////////
$datefromdb = $guest['guest_time'];
$year = substr($datefromdb,0,4);
$mon = substr($datefromdb,4,2);
$day = substr($datefromdb,6,2);
$hour = substr($datefromdb,8,2);
$min = substr($datefromdb,10,2);
$sec = substr($datefromdb,12,2);
$orgdate = date("l F dS, Y h:i A",mktime($hour,$min,$sec,$mon,$day,$year));
?>
Date:
echo $orgdate; ?>
echo $guest['guest_message']; ?>
|
} ?>