Guestbook Php With Text File

Guest book using txt file as log file, simple no need database. so perfectly on static web. let's go guys let's make this soup :D

First : you need 2 file at public folder (www / public) on hosting. whatever you can save like you want.
  1. guestbook.php
  2. guestbook.txt
Now let see what code on guestbook.php :

<?php
//----- get value variable --
 $name = $_POST[name];
 $messages = $_POST[messages];
 $mail = $_POST[mail];
 date_default_timezone_set('Asia/Jakarta');
 $time = date("m-d-y H:i:s");

//---- check value -----
if (empty($name) or empty($messages)){
?>
<html>
<body>
<form id="guestbook" name="guestbook" method="post" action="<? $PHP_SELF ?>">
<table border="0">
  <tr>
    <td><h2><strong><u>Guestbook</u></strong></h2></td>
  <tr>
    <td>name :</td>
    <td><input type="text" name="name"/></td>
    </tr>
  <tr>
  <tr>
    <td>email :</td>
    <td><input type="text" name="mail"/></td>
    </tr>
  <tr>
    <td valign="top">messages :</td>
    <td><textarea name="messages" cols="45" rows="5"></textarea></td>
    </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input type="submit" value="Send" /></td>
    </tr>
</table>
</form>
</body>
</html>
<?php
}
 else
 {
 //--- write messages to file txt ---
    $myFile = "guestbook.txt";
    $fh = fopen($myFile, 'a') or die("file unlocated");
    fwrite($fh, "name  = ".$name."\n");
    fwrite($fh, "time = ".$time."\n");
    fwrite($fh, "time = ".$mail."\n");
    fwrite($fh, "messages = ".$messages."\n\n");
    fclose($fh);
 //--- showing messages after sending --
    ?>
    back click <a href="http://localhost/guestbook.php"> <h3>here</h3></a>
    <?php
}
?>

2 Responses to "Guestbook Php With Text File"

  1. Bacalah berita jawa timur hari ini :

    Sekolah Tatap Muka di Batu Batal, Dewanti Rumpoko Minta Tak Dibandingkan Dengan Pembukaan Wisata

    https://jatimtimes.com/baca/232674/20210105/114500/sekolah-tatap-muka-di-batu-batal-dewanti-rumpoko-minta-tak-dibandingkan-dengan-pembukaan-wisata

    ReplyDelete
    Replies
    1. Bacalah berita jawa timur hari ini :

      Sekolah Tatap Muka di Batu Batal, Dewanti Rumpoko Minta Tak Dibandingkan Dengan Pembukaan Wisata

      Klik disini

      Delete