Guestbook Php With Text File
First : you need 2 file at public folder (www / public) on hosting. whatever you can save like you want.
- guestbook.php
- guestbook.txt
<?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> </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, "mail = ".$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
}
?>
Join the conversation