//////////////////////////////// // 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. //////////////////////////////// $hostname="p41mysql39.secureserver.net"; $username="ssadiq"; $password="HarMar01"; $dbname="ssadiq"; mysql_connect($hostname,$username, $password) or die ("Unable to select SQL Server! Please try again later."); mysql_select_db($dbname) or die("Unable to select database"); //////////////////////////////// // 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_query($query) or die("Insert Failed!"); } 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. //////////////////////////////// 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']; ?> | ||