Jump to content

Guestbook

- - - - -

  • Please log in to reply
18 replies to this topic

#1
hoku_2000 _99

hoku_2000 _99

    Learning Programmer

  • Members
  • PipPipPip
  • 67 posts
I currently have this php guest book example that I found, but when I run it I get two errors:

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;
}
?>



#2
Vaielab

Vaielab

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 547 posts
Line 55: if ($_POST['message']){

Line 117: if ($extrapages != 0){

The error for the line 55 is their is no variable message inside of $_POST, you need to test it before like so:
if (isset($_POST['message'])) { 

  if ($_POST['message']){

    ...

  }

}


And the error on line 117 is because you don't always initialise the variable $extrapages
$extrapages will only be initialised if you enter the if on line 76 (if(count($array)>15){)
So just before this if, you need to add an default value for $extrapages like so $extrapages = 0; (0 is the correct value if I look at your code on line 117 (if ($extrapages != 0){)

#3
hoku_2000 _99

hoku_2000 _99

    Learning Programmer

  • Members
  • PipPipPip
  • 67 posts
Now I've made the changes and I get no errors. How can I now adjust the time to read the time such as 1:00 PM (not 20:00 PM) and how can I fix my error if the user submits no comment (The error message 'Please leave your comment') is suppose to show. Also, is there a way that I can clear the entries I've posted when I was testing it? When I actually put my php file on my FTP, the entries from when I tested it show up.

<?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 (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) == 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;
}
?> 



---------- Post added at 01:43 PM ---------- Previous post was at 01:26 PM ----------

I think I may have found a way to clear my entries, I used $array = array(); but my question is, if I use it on my website, will it clear the entries a user puts in or now? I just wanted the guestbook to be blank on my website until someone signs it.

#4
Vaielab

Vaielab

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 547 posts
For your time, I'm guessing the problem is because of the time zone. You should always specify the timezone in your program. In the first cople of line put this code
date_default_timezone_set('America/Montreal');
Here are the list of the supported time zone PHP: List of Supported Timezones - Manual

For an error message you have to test the comment.
First initialise a variable that will contain the error message and than test if the message have a length, is it don't put an message in the variable like so

$errorMsg = '';

if (isset($_POST['message']) && strlen($_POST['message'])){ //Modified here, if strlen (number of car is 0 it will return false), you should maybe trim it


    //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']}");

}

else {

$errorMsg = 'You have to write a comment!';

}



And later in your code, you simply print the $errorMsg variable.
If their no variable you will print a empty string. If it has an error you will print the variable. But you won't get any error since you initialised it before.


ANd for your cleaning the entry, i'm not too certain what you mean by that... do you mean at reload, or delete everything, or...

#5
hoku_2000 _99

hoku_2000 _99

    Learning Programmer

  • Members
  • PipPipPip
  • 67 posts
I added the changes, but I am not to sure if I deleted or didnt add something that I needed cause I am now getting this error : Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\xampp\gbook.php on line 60

And about cleaning my entry, what I mean is how do I delete the entries that I have in there that I posted while I was testing it. As of now, I have some entries that I would like to get rid of until the client uses it.

Also, I was looking at the different locations to adjust the time, is some sort of php that I could put that depending on the user, the time shows up in there timezone. For example, someone who lives on the east coast will see est, while someone on the west coast viewing the website sees what the east coast user sees, but in there timezone.


<?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
////////////////////////////

  $errorMsg = '';
if (isset($_POST['message']) && strlen trim($_POST['message'])){ //Modified here, if strlen 

(number of car is 0 it will return false), you should maybe trim it

    //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']}");
}
else {
$errorMsg = 'You have to write a comment!';
}
}

//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;
}
?> 




#6
Vaielab

Vaielab

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 547 posts
Did you look at your line 60?
It's part of my comment that isn't in comment anymore, you can simply delete it and it should work

To clean your code you need to delete the row in the sql, if you have phpmyadmin installed on your server it will be quite easy, just explore it a little bit

And for the timezone different for everyone, you can either make a log system with username/password and one of the setting would be the timezone, or you could use some javascript to write the time inside a input text or hidden, and post it... but this would not be the best idea, since a user could modify it to anything (a post made from the year 99999)

#7
hoku_2000 _99

hoku_2000 _99

    Learning Programmer

  • Members
  • PipPipPip
  • 67 posts
I deleted it, and now I get the following:

Warning: is_file() expects exactly 1 parameter, 0 given in C:\xampp\htdocs\xampp\gbook.php on line 40

Warning: sqlite_open() expects at least 1 parameter, 0 given in C:\xampp\htdocs\xampp\gbook.php on line 42

Warning: sqlite_query() expects parameter 1 to be resource, string given in C:\xampp\htdocs\xampp\gbook.php on line 45

Warning: sqlite_single_query() expects parameter 1 to be resource, string given in C:\xampp\htdocs\xampp\gbook.php on line 81

Notice: Use of undefined constant rest - assumed 'rest' in C:\xampp\htdocs\xampp\gbook.php on line 24



<?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()){
    //Open a connection
    $dbc = sqlite_open();
    //Create table
    $query = "CREATE TABLE guestbook (inputId PRIMARY KEY, inputText TEXT NOT NULL);";
    sqlite_query($dbc,$query);

} else {
    //Open a connection
    $dbc = sqlite_open();
}




////////////////////////////
//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) == 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;
}
?> 



---------- Post added at 07:07 PM ---------- Previous post was at 06:34 PM ----------

Would I use the following to delete my entries that I have?

db_connect(); 

$query = "DELETE FROM tablename WHERE id = ('$id')"; 

$result = mysql_query($query); 

echo "The data has been deleted."; 

?> 


#8
Vaielab

Vaielab

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 547 posts
Did you read the error?
Line 40 : if (!is_file()){ you go to php.net and search for the function is_file PHP: is_file - Manual
You will see that you need to pass 1 argument (like the error said) and this argument would be the name of the file to test if it exist.
So you need to add a string with a filename, where you have permission to write

Than line 42, same error, sqllite use file as database, so you will need to give 1 argument with the filename (the one you just tested).

You will have the same error on line 49, once the file is created

Error on line 45 & 81 are because you could not connect to the database on line 42, so when you will correct your error on line 42, thoses error will go away

Warning on line 24, even if it's only a warning you should always correct them, once against it's simply a comment that you add line in the middle. You can either comment the line 24 or delete it



In your code to delete:
the function db_connect() dosen't exist
And you use sqlite to write, but mysql to delete, this won't work, you need a sqlite statement to delete your data, or modify your code to insert your data with mysql

#9
hoku_2000 _99

hoku_2000 _99

    Learning Programmer

  • Members
  • PipPipPip
  • 67 posts
Did I create my database right or did I have to create another file?

<?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")){
    //Open a connection
    $dbc = sqlite_open("CREATE DATABASE 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("data");
}




////////////////////////////
//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;
}
?> 




#10
Vaielab

Vaielab

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 547 posts
Before we continu, you should read this tutorial: PHP Tutorial - Creating and Modifying SQLite Databases | Switch on the Code

#11
hoku_2000 _99

hoku_2000 _99

    Learning Programmer

  • Members
  • PipPipPip
  • 67 posts
This is my frist time using sqlite, so, is this how should I have done it?



  try 
{
  //create or open the database
  $database = new SQLiteDatabase('data.sqlite', 0666, $error);
}
catch(Exception $e) 
{
  die($error);
}


#12
Vaielab

Vaielab

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 547 posts
Yes this will connect you to the database




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users