Results 1 to 4 of 4

Thread: Creating A Guestbook Using PHP?

  1. #1
    Join Date
    May 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Creating A Guestbook Using PHP?

    I am having trouble creating a guestbook using php? I used functions but when I upload it to the server that I am using it is saying that my closing </html> tag is missing something. I have no idea what it is either. I was wondering if someone could help me out and take a look at my code.

    <?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Guestbook</title>
    <head>
    <style type="text/css">
    body {background-color: #FFCCCC}
    h1 {color: #9966FF}
    b, p {color: #9966FF}
    </style>
    </head>

    <body>
    <?php
    // data grabbing here/
    $fname = $_POST ['fname'];
    $lname = $_POST ['lname'];
    $gender = $_POST ['gender'];
    $comment = $_POST ['comment'];
    $submit = $_POST ['submit'];

    function displayContents ($guestbookfile)
    {
    @$mf = fopen("../guestbook/guestbook.txt", "r");
    if (!$mf)
    {
    $out = "<p class\"err\">Could not open the guestbook file for reading!</p>";
    }
    else
    {
    while (!feof($mf))
    {
    $entry = fgets($mf, 3000);
    if (!feof($mf))
    {
    $data = explode("\t", $entry);
    $out .= "<blockquote><span class=\"quote\">" . stripslashes($data [7]) ."</span><br />";
    $out .= "<cite>-<span class=\"author\">$data[3] $data[4]</span><br /";
    $out .= "A $data[5] $data[6]<br />";
    $out .= "From $data [2]<br />";
    $out .= "at $data[0] on $data[1]";
    $out .= "</cite></blockquote>\n";
    }
    }
    fclose($mf);
    }
    return $out;
    }

    function displayForm($fname, $lname, $gender, $comment, $err)
    {
    echo "err\n";
    ?>
    <form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post">
    <div>
    <p><b>First Name:<br />
    <input type="text" name="fname" id="fname" value="<?php echo $fname; ?>" /><br />
    <br>
    <p>Last Name:<br />
    <input type="text" name="lname" id="lname" value="<?php echo $lname; ?>"/><br />
    <br>
    <p><b>Gender<br />
    <label for="male">Male: </label><input type="radio" name="gender" id="male" value="male" <?php if ($gender == "male") echo "checked=\"checked\""; ?> /> &nbsp; &nbsp; <label for="female">Female: </label><input type="radio" name="gender" id="female" value="female" <?php if ($gender == "female") echo "checked=\"checked\""; ?> />
    <p><b>Leave Some Feedback:<br />
    <textarea name="comment" id="coment" rows="5" cols="25" <?php echo $comment; ?> /></textarea><br />
    <br>
    <input type="submit" name="submit" value="Submit" />
    </form>
    <?php
    }

    function insertData($outstring, $guestbook)
    {
    @$mf = fopen($gbFile, "a");
    if (!$mf)
    {
    $err = "<p class=\"err\">Could not open guestbook file for writing!</p>";
    }
    else
    {
    if (flock($mf, LOCK_EX))
    {
    fwrite($mf, $outstring);
    flock($mf, LOCK_UN);
    fclose($mf);
    $err = "success!";
    }
    else
    {
    $err = "<p class=\"err\">Could not establish a file lock!</p>";
    }
    }
    return $err;
    }
    function processData($fname, $lname, $gender, $comment)
    {
    $outstring = date('h:i a') . "\t" . date('j F, Y') . "\t";
    $outstring .= $_SERVER['REMOTE_ADDR'] . "\t";
    $outstring .= addslashes(trim($fname)) . "\t" . addslashes(trim($lname)) . "\t";
    $outstring .= $gender . "\t";
    $outstring .= addslashes(trim($comment)) . "\n";
    $err = insertData($outstring, "../guestbook/guestbook.txt");
    if ($err = "success!")
    {
    echo displayContents("../guestbook/guestbook.txt");
    }
    else
    {
    echo $err;
    }

    function valid($fname, $lname, $gender, $comment)
    {
    if (is_null($fname) || empty($fname) || $fname == "") $err .= "Please enter your first name<br />";
    if (is_null($lname) || empty($lname) || $lname == "") $err .= "Please enter your last name<br />";
    if ($gender != "male" && $gender != "female") $err .= "Please indicate your sex<br />";
    if (is_null($comment) || empty($comment) || $comment == "") $err .= "Please leave me some comments<br />";
    return $err;
    }
    ?>
    </head>

    <body><div id="main">
    <?php
    if ($submit == 'Submit') {
    $err = valid($fname, $lname, $gender, $comment);
    if ($err == "")
    {
    processData($fname, $lname, $gender, $comment);
    exit;
    }
    }
    if ($err == "")
    {
    $err = "<p>Plase fill out the following form:</p>";
    }
    else
    {
    $err = "<p class=\"err\">Please make the following corrections:<br />\n$err\n</p>";
    }
    displayForm($fname, $lname, $gender, $comment, $err);
    ?>
    </div>
    </body>
    </html>

  2. #2
    Join Date
    May 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb O-k

    Very nice script very big. The problam would be that you have added dud scripting. My advise would be to find out were you got the scriot from or write it out again there is a posibility, I also fixed a bit of it !!! I carnt seem to get rid of the text and moke it code!!!

    Here it is:

    <?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Guestbook</title>
    <head>
    <style type="text/css">
    body {background-color: #FFCCCC}
    h1 {color: #9966FF}
    b, p {color: #9966FF}
    </style>
    </head>

    <body>
    <?php
    // data grabbing here/
    $fname = $_POST ['fname'];
    $lname = $_POST ['lname'];
    $gender = $_POST ['gender'];
    $comment = $_POST ['comment'];
    $submit = $_POST ['submit'];

    function displayContents ($guestbookfile)
    {
    @$mf = fopen("../guestbook/guestbook.txt", "r");
    if (!$mf)
    {
    $out = "<p class\"err\">Could not open the guestbook file for reading!</p>";
    }
    else
    {
    while (!feof($mf))
    {
    $entry = fgets($mf, 3000);
    if (!feof($mf))
    {
    $data = explode("\t", $entry);
    $out .= "<blockquote><span class=\"quote\">" . stripslashes($data [7]) ."</span><br />";
    $out .= "<cite>-<span class=\"author\">$data[3] $data[4]</span><br /";
    $out .= "A $data[5] $data[6]<br />";
    $out .= "From $data [2]<br />";
    $out .= "at $data[0] on $data[1]";
    $out .= "</cite></blockquote>\n";
    }
    }
    fclose($mf);
    }
    return $out;
    }

    function displayForm($fname, $lname, $gender, $comment, $err)
    {
    echo "err\n";
    ?>
    <form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" od="post">
    <div>
    <p><b>First Name:<br />
    <input type="text" name="fname" id="fname" value=" " size="40" tabindex="40" /><br />
    <br>
    <p>Last Name:<br />
    <input type="text" name="lname" id="lname" size="40" tabindex="40"/><br />
    <br>
    <p><b>Gender<br />
    <label for="male">Male: </label><input type="radio" name="gender" id="male" value="male" <?php if ($gender == "male") echo "checked=\"checked\""; />&nbsp;&nbsp;&nbsp;&nbsp; <label for="female">
    Female: </label><input type="radio" name="gender" id="female" value="female" <?php if ($gender == "female") echo "checked=\"checked\""; />
    <p><b>Leave Some Feedback:<br />
    <textarea name="comment" id="coment" rows="5" cols="25" <?php echo $comment; /></textarea><br />
    <br>
    <input type="submit" name="submit" value="Submit" />
    </form>
    <?php
    }

    function insertData($outstring, $guestbook)
    {
    @$mf = fopen($gbFile, "a");
    if (!$mf)
    {
    $err = "<p class=\"err\">Could not open guestbook file for writing!</p>";
    }
    else
    {
    if (flock($mf, LOCK_EX))
    {
    fwrite($mf, $outstring);
    flock($mf, LOCK_UN);
    fclose($mf);
    $err = "success!!!";
    }
    else
    {
    $err = "<p class=\"err\">Could not establish a file lock!</p>";
    }
    }
    return $err;
    }
    function processData($fname, $lname, $gender, $comment)
    {
    $outstring = date('h:i a') . "\t" . date('j F, Y') . "\t";
    $outstring .= $_SERVER['REMOTE_ADDR'] . "\t";
    $outstring .= addslashes(trim($fname)) . "\t" . addslashes(trim($lname)) . "\t";
    $outstring .= $gender . "\t";
    $outstring .= addslashes(trim($comment)) . "\n";
    $err = insertData($outstring, "../guestbook/guestbook.txt");
    if ($err = "success!")
    {
    echo displayContents("../guestbook/guestbook.txt");
    }
    else
    {
    echo $err;
    }

    function valid($fname, $lname, $gender, $comment)
    {
    if (is_null($fname) || empty($fname) || $fname == "") $err .= "Please enter your first name<br />";
    if (is_null($lname) || empty($lname) || $lname == "") $err .= "Please enter your last name<br />";
    if ($gender != "male" && $gender != "female") $err .= "Please indicate your <br />";
    if (is_null($comment) || empty($comment) || $comment == "") $err .= "Please leave me some comments<br />";
    return $err;
    }
    ?>
    </head>

    <body><div id="main">
    <?php
    if ($submit == 'Submit') {
    $err = valid($fname, $lname, $gender, $comment);
    if ($err == "")
    {
    processData($fname, $lname, $gender, $comment);
    exit;
    }
    }
    if ($err == "")
    {
    $err = "<p>Plase fill out the following form:</p>";
    }
    else
    {
    $err = "<p class=\"err\">Please make the following corrections:<br />\n$err\n</p>";
    }
    displayForm($fname, $lname, $gender, $comment, $err);
    ?>
    </div>
    </body>
    </html>

  3. #3
    Join Date
    May 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Just again sorry!!!...

    Quote Originally Posted by Mark_187
    This is 1 i made you can have it if you want!!! FOR FREE!!:

    <html>

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <meta http-equiv="Content-Language" content="en-us">
    <title>New Page 3</title>
    </head>

    <body>

    <p align="center"><b><font size="5">Guest Book</font></b></p>
    <hr>
    <p>&nbsp;</p>
    <form od="POST" action="--WEBBOT-SELF--">
    <!--webbot bot="SaveResults" u-file="guestlog.htm" s-format="HTML/DL" s-label-fields="TRUE" s-builtin-fields="Date Time REMOTE_USER" s-form-fields -->
    <h2><strong>Add Your Comments</strong></h2>
    <p><textarea name="Comments" rows="8" cols="52"></textarea></p>
    <p><input type="submit" value="Submit Comments">
    <input type="reset" value="Clear Comments"><br>
    <br>
    <em style="font-style: normal"><font size="4">After you submit your
    comments, you will need to reload this page with your browser in order to
    see your additions to the log.</font></em></p>
    </form>
    <hr>

    </body>

    </html>

  4. #4
    Join Date
    May 2005
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i tried using the one you made, and when i hit submit, it says cannot find page or whatever. it tries to got to --WEBBOT-SELF-- does this require a programm or something???

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •