saxchick1
09-24-2011, 11:42 PM
I am using SQLite for my guestbook and right now my time is not in the right format, right now it reads something like 21:03, when I would like it to read something like 1:00PM. Any help is welcomed! Thanks!
<?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("data.sqlite")){
//Open a connection
$dbc = sqlite_open("data.sqlite");
//Create table
$query = "CREATE TABLE guestbook (inputId PRIMARY KEY, inputText TEXT NOT NULL);";
sqlite_query($dbc,$query);
} else {
//Open a connection
$dbc = sqlite_open("data.sqlite");
}
////////////////////////////
//Part 3: Add new comments and show guestbook
////////////////////////////
if (isset($_POST['message'])){
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
$extrapages = 0;
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;
}
?>
<?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("data.sqlite")){
//Open a connection
$dbc = sqlite_open("data.sqlite");
//Create table
$query = "CREATE TABLE guestbook (inputId PRIMARY KEY, inputText TEXT NOT NULL);";
sqlite_query($dbc,$query);
} else {
//Open a connection
$dbc = sqlite_open("data.sqlite");
}
////////////////////////////
//Part 3: Add new comments and show guestbook
////////////////////////////
if (isset($_POST['message'])){
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
$extrapages = 0;
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;
}
?>