Guestbook Script - (Using Flat Files, no database)

free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > PHP Programming

Guestbook Script - (Using Flat Files, no database)

Pandemonium
Okay, I wrote a cool little Guestbook script a few weeks ago. It is very simple (one page of php) that uses flat files (text files). Using this script, you never need to use a database (you can if you want, but that's up to you). Anyways, here is the php code. Enjoy!

CODE

<?php

print "<form action='whateverthepageis.php' method='post'>";
print "* Your name: " . "<input type='text' name='yourName'>";
print "Email: " . "<input type = 'text' name = 'email'><br>";
print "Website URL: " . "<input type = 'text' name = 'webUrl'>";
print "Website Name: " . "<input type = 'text' name = 'webName'><br>";
print "* Comments: " . "<textarea name='comments'></textarea>";
print "<input type='submit' value='submit'>";
print "</form>";

print "<table>";
if(strlen($yourName) > 4 and strlen($comments) > 10)
{
    $newEmail = "<a href='mailto:" . $email . "'>" . $email . "</a>";
    $newWebUrl = "<a href='". $webUrl."'>". $webUrl . "</a>";

    $fileID = fopen('post.txt', 'a');
    fputs($fileID, "Name: " . $yourName);
    fputs($fileID, "Email: " . $newEmail);
    fputs($fileID, "Website Name: " . $webName);
    fputs($fileID, "Website URL: " . $newWebUrl);
    fputs($fileID, "Comments: " . $comments);
    fclose($fileID);

    $fileID = fopen('post.txt', 'r');
    while(!feof($fileID))
    {
          $gbookLine = fgets($fileID);
          print "<tr><td>" . $gbookLine. "</td></tr>";
    }    
    fclose($fileID);
}
print "</table>";

?>


By the way, if there is an error, I'll correct it.

 

 

 


Reply

Spectre
Here it is re-written for use with a MySQL database.

Please note that it is a simple, 'on-the-fly' script, so it mightn't be perfect or bugless.

I've also changed one or two things to suit the style in which I usually code. I hope you don't mind, Pandemonium.

CODE
<?php

$sql_db = "guestbook";
$sql_user = "";
$sql_pass = "";
// Make sure you set these variables. The rest can remain unedited,
// assuming you don't want anything else changed.

if(isset($_POST['yourName']) && isset($_POST['comments'])) {
    $name = $_POST['yourName'];
    if(isset($_POST['email'])) { $email = $_POST['email']; }
    if(isset($_POST['webUrl'])) { $url = $_POST['webUrl']; }
    if(isset($_POST['webName'])) { $website = $_POST['webName']; }
    $comments = $_POST['comments'];
    
    mysql_connect("localhost", $sql_user, $sql_pass);
    mysql_select_db($sql_db);
    mysql_query("INSERT INTO guestbook VALUES (0, '$name', '$email', '$url', '$website', '$comments')");
    mysql_close();
}
?>

<p><form action="<?php echo("http://" . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME']); ?>" method="post">
* Your name: <input type="text" name="yourName">
Email: <input type = "text" name = "email"><br>
Website URL: <input type = "text" name = "webUrl">
Website Name: <input type = "text" name = "webName"><br>
* Comments: <textarea name="comments"></textarea>
<input type="submit" value="submit">
</form></p><p><hr></p><p>

<?php
mysql_connect("localhost", $sql_user, $sql_pass);
mysql_select_db($sql_db);
$result = mysql_query("SELECT * FROM guestbook");
if($result) {
    while($data = mysql_fetch_assoc($result)) {
 echo "<p><b>Name:</b> " . $data['name'] . "<br>\n";
 if(isset($data['email'])) {
     echo "<b>Email:</b> <a href=\"mailto:" . $data['email'] . "\">" . $data['email'] . "</a><br>\n";
 }
 if(isset($data['url'])) {
     echo "<b>Website:</b> <a href=\"" . $data['url'] . "\" target=\"_BLANK\">";
     if(isset($data['website'])) {
   echo $data['website'];
     } else {
   echo $data['url'];
     }
     echo "</a><br>\n";
 }
 echo "<b>Comments:</b><br>\n" . $data['comments'];
 echo "</p>\n<hr>\n";
    }
}
mysql_close();

echo "</p>";

// Script originally created by Pandemonium for use with a flat-file database.
// Re-written for use with MySQL by Spectre.
?>


Here is the table which I used as well (phpMyAdmin dump):

CODE
CREATE TABLE `guestbook` (
 `id` int(5) NOT NULL auto_increment,
 `name` text NOT NULL,
 `email` varchar(30) NOT NULL default '',
 `url` varchar(30) NOT NULL default '',
 `website` text NOT NULL,
 `comments` text NOT NULL,
 PRIMARY KEY  (`id`)
) TYPE=MyISAM AUTO_INCREMENT=4;


This query could be run directly from a PHP script if you want, as long as a connection to MySQL has been established and a database selected.

Keep up the good work, Pandemonium.

 

 

 


Reply

Pandemonium
Nice work there Spectre. And no, I don't mind if you changed some of it. smile.gif But thanks for the compliment. I may post some more scripts sometime.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Recent Queries:-
  1. wappy guestbook script - 672.39 hr back. (1)
Similar Topics

Keywords : guestbook, script, flat, files, database

  1. How To Make Php Newsletter Script
    (3)
  2. Php Guest Online Script
    (3)
    make an index.php copy and paste this code CODE <?php $db_host = "localhost";
    $db_user = "root"; $db_pass = ""; $db_name = "test";
    $dbc = mysql_connect($db_host, $db_user, $db_pass); $dbs =
    mysql_select_db($db_name); $tm = time(); $timeout = $tm -
    (30*60);
    if($_SERVER["REMOTE_ADDR"]){$ip=$_SERVER["REMOTE_ADDR
    "];} else{$ip=$_SERVER["HTTP_X_FORWARDED_FOR"];}....
  3. How To Make A View New Post Script?
    (5)
    Ok so i'm still working on the forum software i posted about a while back, but I have no idea
    how to do this. I want to make a view new post script, as this is one of the main things that my
    forum software dose not have that all other forums have. so does any body have an idea on how i
    would do this? Thanks.....
  4. Guessing Php Script
    (2)
    I am looking for: freeware php quess the person in the photo game script....
  5. Ms-access Database Question
    Allowing Web Access to the Informaton (3)
    Hi. I wanna know if there is a way of accessing an MS-Access database so that my site can extract
    data from it and make it avilable online. I have an accounting package that saves everthing in an
    MDB file and I want that info available for my clients from whereever thay are. Split Topic ....
  6. Need Help Installing Dolphin Community Script!
    (5)
    I'm not sure if this is the right place to post this but I really need help in installing the
    dolphin community script. I have absolutely no previous experience of scripts or programming. I
    would really appreciate if someone could walk me through it step-by-step, or even do it for me by
    logging into my cpanel. I have tried to install it my self but I'm a little confused. I'm
    sure it won't take very long at all for someone who has done this before.....
  7. Need Some Help In File Browser
    listing all sub folders and files in them. (8)
    Hey I want to create a very simple file browser, so that, it reads all the sub-folders which are
    places in a directory, and the files inside the sub-folders (It reads only files inside sub-folders
    and list them in simply. ) Also, it creates a directory (any name) inside each sub folder. My
    Following code reads on the files inside the main directory, it does not read the files inside the
    sub-folders.. I appreciate any help. CODE <? $path = "./"; $dir_handle =
    @opendir($path) or die("Unable to open $path"); whil....
  8. How Do I Connect To Live Database With Php Script?
    while being hosted with ComputingHost (6)
    I am not new to programming. I want to create a form to add some values into my tables, the code
    are all working. But I am not sure what is the URL to connect to my site's database. All along,
    I have been testing through MAMP, which provides a local copy of mySQL. Can anyone lend me a hand?
    My site's URL is http://limetouch.com/ ....
  9. Download Script For Mp3 Files
    (0)
    Hello, I'm looking for a download script for sound files (e.g. mp3, avi, wma, and other ones).
    i have found a few download scripts but they would not work for sound files for some reason. also
    this will not be used for allowing downloading of illegal or riped music, what i will be using this
    script for is i'm making a site for my church and the pastor wants to be able to recored the
    services and then have me upload them to the site so that the church members can download them for
    what ever reason. If some one could tell me how to make one or could show me a plac....
  10. Php Rediret Script
    (12)
    Ok, what I am trying to do is this. Re-direct a domain name called: avalon.asn.au to
    preschool.stmarksavalon.org.au I have created a script that will re-direct within the a folder.
    However, the avalon.asn.au and stmarksavalon.org.au are PARKED Domains. Any ideas on how to create
    this PHP Redirect Script please?....
  11. Forum Script
    (3)
    Hello, i'm wanting to start making my own forum software but i dont know where to start or what
    i need to know in order to do this. I know i will need php and mysql but what else, and could some
    one point me to a good site were i could learn php and mysql. Thanks ....
  12. How Would I Go About Making A Simple "counting" Script?
    (3)
    I plan on making a script for basic voting between different options, and I'd like to know what
    PHP coding I would require. Basically, each choice will be as simple as this: CODE <form
    method="post" action="process.php"> Best falsetto?<br><br>
    <input type="radio" name="1"> Person A<br> <input
    type="radio" name="2"> Person B<br> <input type="submit"
    value="Submit"> </form> What PHP would be used to basically add 1 value to a....
  13. Library Script
    Where? (6)
    Hello, everyone. Anyone knows where I can get a library script that acts like CMS script software,
    you can add books or delete them. I want to build virtual online library which can be accessible to
    everyone. Or just give me some advices how to make it build. I'm a novice in programming.....
  14. Script Not Working
    I don't know why. (6)
    For some reason my random string script is not working. I got a fatal error when I tried it under
    XAMPP. I do not know why. It looks syntatically correct. Could someone help me? Here is the script:
    (Warning its over 100 lines long) //This PHP script will generate a random array and turn it into
    a string consisting of 0-9 and A-Z. // This is the first developmental version. //Create 10 item
    array for string $string = array(0,0,0,0,0,0,0,0,0,0); //Create function to replace 10-36 with
    A-Z function conToStr() { for ($a = 0;$a switch($string ) { ....
  15. Script Help Required: Undefined Variable
    A fault I cannot spot in PHP (3)
    Hi, when running a PHP script I keep getting the error: QUOTE Notice: Undefined variable: bret
    in c:\program files\easyphp1-8\home\poll.php on line 294 Notice: Undefined
    variable: bret in c:\program files\easyphp1-8\home\poll.php on line 294 (And,
    yes, I get it twice). The code related to the variable is as follows: CODE function
    LogString($string,$type)     {         $t_log = "\n";
            $t_log .=
    $this->globaldata->server_vars['REMOTE_ADDR']."....
  16. Php Downloads Script
    (4)
    I've been looking all over the net for a PHP script which can provide an interface to browse a
    downloads database. The database could be powered by MySQL. If you know a script like this, please
    post it here. Thanks in advance, Ironchicken.....
  17. Html Code Tester. Online Script
    (15)
    Yes, yes. I have another script that I have written and I am distributing. I am not entirely sure if
    this works. I have not tested it yet, but I will later and post back with a demo and fix it up.
    Current script: CODE <?php //Save this as something like htmltest.php function
    CheckForm() { $html_unsafe=$_POST['code']; //Gives us our user
    input $html_safe=str_replace("<?php"," ",$html_unsafe);
    //Starts security measures $html_safe=str_replace("?>","
    ",$html_sa....
  18. Very Simple Online Now Script
    This is a very simple online now script. (4)
    Hi all, Its Aldo. anyways, I wont be using the method of pagination, i will just tell you how to
    make a basic online now script. When someone logs in, now take into consideration that the name of
    the username input is username ( First ,create a table in your database saying online now and add 2
    fields to it. id and username CODE id type=integer(INT) , auto increment, length =255
    and username = VARCHAR length=the limit a username should be in your site now from there we take
    off : CODE <?php //logged.php //authentication script //connection scri....
  19. Creatting A Playlist Through Php
    script help needed (5)
    Hi I am trying to make a script so that i can insert songs into a playlist, but i need a script in
    which it opens the playlist file and removes the closing tag at the end, so before i can add more
    entrys. e.g CODE <atx> <entry>Location 5</entry> <entry>Location
    4</entry> <entry>Location 3</entry> <entry>Location
    2</entry> <entry>Location 1</entry> <atx> But to add more entrys
    i would have to get rid of the atx, then use the fputs to place the new entry into the file. ....
  20. What Kind Of Script Do You Need ?
    post here and get free script (15)
    Hi everybody sorry if i posting here , i know I want design free PHP script and i dont know
    webmasters what kind of scripts want i think its better to aks here becuase trap17 is very nice
    webmasters forum So , Plz post here what kind of script with details you need ! sorry may en
    is not very well for example you need "upload center" : write "upload center" with upload center
    options ( like Ajax , Fast , multi lan and ... ) with this post we can give script details and
    webmasters idea /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.....
  21. Wappy Buddy V1.10 - Tibia Gold Edition By Wappy & Jon Roig
    the official wap download script (3)
    By downloading this script you are agreeing to the license and terms outlined below /biggrin.gif"
    style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" /> QUOTE /** * *
    @package: wappyBUDDY - Tibia Gold Edition * @version: 1.10 2006/10/01 00:00:01 wappy * @copyright:
    ©2003, 2006 jon roig, wappy * @release notes: this is the first official release of my download
    script despite pirate and incomplete copies floating around that were stolen from one of my previous
    servers. The next release will follow very shortly * @terms: wappyBUDDY is free softw....
  22. Free Auction Script
    Any Suggestions? (6)
    Any free auction script suggested? I want it to be as many practical functions as possible, yet
    easy to manage. And more importantly, it is free! Appreciate your kind suggestions!....
  23. Wappychat_oldskool
    old version of my wap chat script :-) (15)
    here is a very old version of my wap chat script, its not very advanced but has privates, smileys
    etc. I will post some further versions (with owner, admin, mod status and profiles) when i have time
    to write the readme/install instructions for them. You will find instructions inside the zip. If you
    have any problems post here but i know it don't work on all servers for some reason but it does
    work on the trap server so will be cool ok /tongue.gif" style="vertical-align:middle" emoid=":P"
    border="0" alt="tongue.gif" /> ....
  24. Watermark Your Image With Simple Php Script
    found it on the net (35)
    This script was found on the net http://tips-scripts.com/?tip=watermark#tip B&T's Tips &
    Scripts site. Just in case the site may not show, I will include the code here: List of things
    needed: 1. your image in any format 2. watermark image--in gif format with transparent background 3.
    script below with name (i.e. watermark.php) CODE <?php // this script creates a watermarked
    image from an image file - can be a .jpg .gif or .png file // where watermark.gif is a mostly
    transparent gif image with the watermark - goes in the same directory as this script // ....
  25. Can You Add Images Into A Mysql Database?
    Using Php? (20)
    I'm learning php in class right now, but I'm still not that good at it, what I'm
    wondering is when I write the php so that it can connect with a database, can I at the same time
    have it that it is able to display back images that I choose. Like, I want a search feature, where
    you can search for a keyword, and it will bring back a list of all the possible entries with that
    keyword, but each of these entries will have a photo associated with it. Now, do I put these image
    files directly into the database, or do I write the code to link them from my files to th....
  26. Parse: Error Unexpected T_lnumber
    php parse error when running script (4)
    Hi. I've just created a php script. The main object of the script is to delete some old files
    and replace it with a new file with some new content, effectively moving the contents from one file
    to another. These are the first 50 lines of the file: /* Calculate For The "A" Group - The
    Latest Games ID */ $a_B = 002; while(file_exists("a_" . $a_B . ".dat")) {
    $a_B++; } $new_page_contents = " " . $_POST . " " . $_POST . "
    include \"/home/cmatcme/public_html/footer.php\"; ?> "; $a_stream = fopen(&....
  27. Script: Php Jukebox
    A one file script! (4)
    This scripts is so simple, you dont need to edit ANY of it! All you have to do is make a folder
    called 'songs' and put some audio files in it. Here is the whole page, I named it index.php
    and put it in a folder called 'music': CODE <!DOCTYPE HTML PUBLIC
    "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd"> <html> <head>
    <title>PHP jukebox</title> </head> <body> <!-- ©2005 Craig
    lloyd. All rights reserved. Visit cragllo.com for more sc....
  28. Change Permission With Php Code
    code to change files' and folders' permissions? (3)
    As everyone know, there two ways (that I can think of) to change files' and directories'
    permissions. One is to change it in your cPanel's Disk Manager and the other is with an FTP
    client that supports chmod. Well, I'm doing something for my site that requires files to have
    full permissions (Execute, Write, and Read on all three groups). At first, I thought that if I made
    the directory 777, then every file created in that directory will be 777 as well. I'm wrong. An
    alternative to doing this is to change each file permission myself, but that would be....
  29. Many Php Script Sites
    (16)
    Hi I find many sites has PHP scripts :: http://www.proxy2.de/scripts.php http://www.free-php.net
    http://knubbe.t35.com/ http://www.ngcoders.com/ http://www.oxyscripts.com/
    http://www.phparena.net/ http://www.1phpstreet.com/ http://px.sklar.com/
    http://www.scoznet.com/ http://php.resourceindex.com/ /blink.gif' border='0'
    style='vertical-align:middle' alt='blink.gif' /> ....
  30. Getting List Of Directories And Files Using Php
    PHP Function for Directory and File List (6)
    is there a php function that lists the content of some folder.... example: /New folder new.txt
    left.gif download.zip dc.exe ....so is there..? /rolleyes.gif' border='0'
    style='vertical-align:middle' alt='rolleyes.gif' /> ....

    1. Looking for guestbook, script, flat, files, database

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for guestbook, script, flat, files, database

*MORE FROM TRAP17.COM*
Similar
How To Make Php Newsletter Script
Php Guest Online Script
How To Make A View New Post Script?
Guessing Php Script
Ms-access Database Question - Allowing Web Access to the Informaton
Need Help Installing Dolphin Community Script!
Need Some Help In File Browser - listing all sub folders and files in them.
How Do I Connect To Live Database With Php Script? - while being hosted with ComputingHost
Download Script For Mp3 Files
Php Rediret Script
Forum Script
How Would I Go About Making A Simple "counting" Script?
Library Script - Where?
Script Not Working - I don't know why.
Script Help Required: Undefined Variable - A fault I cannot spot in PHP
Php Downloads Script
Html Code Tester. Online Script
Very Simple Online Now Script - This is a very simple online now script.
Creatting A Playlist Through Php - script help needed
What Kind Of Script Do You Need ? - post here and get free script
Wappy Buddy V1.10 - Tibia Gold Edition By Wappy & Jon Roig - the official wap download script
Free Auction Script - Any Suggestions?
Wappychat_oldskool - old version of my wap chat script :-)
Watermark Your Image With Simple Php Script - found it on the net
Can You Add Images Into A Mysql Database? - Using Php?
Parse: Error Unexpected T_lnumber - php parse error when running script
Script: Php Jukebox - A one file script!
Change Permission With Php Code - code to change files' and folders' permissions?
Many Php Script Sites
Getting List Of Directories And Files Using Php - PHP Function for Directory and File List
advertisement



Guestbook Script - (Using Flat Files, no database)



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE