Notice: Undefined index: message in C:\xampp\htdocs\xampp\guest.php on line 55
Notice: Undefined variable: extrapages in C:\xampp\htdocs\xampp\guest.php on line 117
This is my first time attempting to make a guestbook. Also, I would like to modify the time. When I added an entry the time read 19:07 PM when I would like it to read 6:07 PM. Not too sure if this is a good example, but just to get the hang of what I am looking for.
<?php
////////////////////////////
//Part 1: Script Setup
////////////////////////////
ob_start();
//We need to strip the slashes that have been added to our POST data!
if (ini_get('magic_quotes_gpc')) {
function array_clean(&$value) {
$value = stripslashes($value);
}
//php 5+ only
array_walk_recursive($_GET, 'array_clean');
array_walk_recursive($_POST, 'array_clean');
}
// Cleans text of all bad characters
function sanitize_text(&$text){
//Delete anything that isn't a letter, number, or common symbol - then HTML encode the rest.
trim(htmlentities(preg_replace("/([^a-z0-9!@#$%^&*()_\-+\]\[{}\s\n<>:\\/\.,\?;'\"]+)/i", '', $text), ENT_QUOTES, 'UTF-8'));
}
////////////////////////////
//Part 2: Connect to DB
////////////////////////////
//If the DB file does NOT exist - Create it
if (!is_file("philip_data")){
//Open a connection
$dbc = sqlite_open("philip_data");
//Create table
$query = "CREATE TABLE guestbook (inputId PRIMARY KEY, inputText TEXT NOT NULL);";
sqlite_query($dbc,$query);
} else {
//Open a connection
$dbc = sqlite_open("philip_data");
}
////////////////////////////
//Part 3: Add new comments and show guestbook
////////////////////////////
if ($_POST['message']){
//Clean the Message
sanitize_text($_POST['message']);
//Clean the Name
sanitize_text($_POST['name']);
$tid = date("H:i:s m-d-y");
//Create Guest Book log
$mess = "<b>Posted by: <i>{$_POST['name']}</i> on $tid</b><br/><br/>{$_POST['message']}<br/><hr/>";
$query = "INSERT INTO guestbook (inputText) VALUES ('$mess');";
sqlite_query($dbc,$query);
header("Location: {$_SERVER['PHP_SELF']}");
}
//Select all the entries
$query = "SELECT inputText FROM guestbook ORDER BY inputId DESC;";
$array = sqlite_single_query($dbc,$query);
//If more than 15 pages
if(count($array)>15){
$extrapages = floor(count($array)/15);
$extrapages++;
if (count($array)%15 == 0){
$extrapages--;
}
if($_GET['page']){
$num = (int)$_GET['page'] * 15;
for($i=$num;$i<count($array);$i++){
$extra[] = array_pop($array);
}
for($i=0;$i<$num-15;$i++){
$extra[] = array_shift($array);
}
} else {
for($i=15;$i<count($array);$i++){
$extra[] = array_pop($array);
}
}
}
$return_to = $_SERVER['PHP_SELF'];
sanitize_text($return_to);
echo "<table border=\"0\" cellpadding=\"10\" cols=\"50\">"
. "<tr><td><form action=\"$return_to\" method=\"POST\">"
. "<b>Name: </b><input type=\"text\" name=\"name\" /><br/>"
. "<b>Comment:</b><br/><textarea cols=\"30\" rows=\"10\" name=\"message\"></textarea><br/>"
. "<input type=\"submit\" /></form></td></tr>";
if($array && is_array($array)){
foreach ($array as $input){
echo "<tr><td width=\"20\">$input</td></tr>\n";
}
} elseif ($array){
echo "<tr><td width=\"20\">$array</td></tr>";
} else {
echo "<td><tr>Please leave a comment.</td></tr>";
}
echo "</table>";
if ($extrapages != 0){
echo extrapages($extrapages);
}
function extrapages($num){
$to = "<table borders=\"0\" cellpadding=\"10\"><tr><td>";
for($i=0;$i<$num;$i++){
$top = $i+1;
$to .= "<a href=\"?page=$top\">$top</a> ";
}
$to .= "</td></tr></table>";
return $to;
}
?>


Sign In
Create Account


Back to top









