Buscar

Membuat Komentar Buku Tamu dengan File Text

Cara membuat komentar di buku tamu sederhana :


1. Sediakan file 2 file.txt dan disimpan di folder tempat kerja anda, 

    misal beri nama  komentar.txt dan jumlah.txt
2. Buat file php dengan nama index.php  dan masukan source code berikut :
<html>
<head>
<title>komentar</title>
</head>
<body>
<form action="bukutamu.php" enctype="multipart/form-data" method="post" name="form1">
    <table align="center" border="0" cellpadding="0" cellspacing="1" style="font-family: Verdana, Geneva, sans-serif; font-size: 12px; width: 500px;">
<tr>
            <td width="9%">Nama</td>
            <td width="91%"><input id="nama" name="nama" size="20" type="text" /></td>
        </tr>
<tr>
            <td>Email</td>
            <td><input name="email" size="20" type="text" /></td>
        </tr>
<tr>
            <td>Komentar</td>
            <td><textarea cols="50" id="komentar" name="komentar" rows="5"></textarea></td>
        </tr>
<tr>
            <td> </td>
            <td><input name="submit" type="submit" value="Submit" />
          <input name="reset" type="reset" value="reset" /></td>
        </tr>
</table>
</form>
<div align="center">
<span style="color: red; font-family: Verdana, Geneva, sans-serif;"> komentar</span>
</div>
</body>
</html><span style="font-family: Verdana,sans-serif; font-size: small;">
</span>

3. Buat file php dengan nama bukutamu.php dan masukan source code 

    berikut :
<span style="font-size: small;">
<span style="font-size: x-small;"><span style="font-family: Verdana,sans-serif;">

$nama   = $_POST['nama'];
$komentar  = $_POST['komentar'];
$email  = $_POST['email'];
$waktu   = date("d-m-y | H:i:s");
$nf   = "komentar.txt";
$fp   = fopen($nf,"r+"); 
$data   = fgets ($fp,50); 
$comfile = file($nf); 
rewind($fp); 
fwrite($fp, </span></span>
'</span><table bgcolor="#0099FF" cellpadding="5" font-size:11px="" geneva="" sans-serif="" style="margin-left: 0px; margin-right: auto; text-align: left; width: 500px;">
<tbody>
<tr bgcolor="#FF6699"><td width="250"><span geneva="" sans-serif="" style="color: black; font-family: Verdana,; font-size: small;">nama : </span><span style="font-size: small;"> <span geneva="" sans-serif="" style="color: #0000cc; font-family: Verdana,;">'.$nama.'</span></span> <br />
<span geneva="" sans-serif="" style="color: black; font-family: Verdana,; font-size: small;">email :  <span geneva="" sans-serif="" style="color: #0000cc; font-family: Verdana,;">'.$email.'</span></span></td><td><span geneva="" sans-serif="" style="color: black; font-family: Verdana,; font-size: small;">tanggal : </span><span style="font-size: small;"> <span geneva="" sans-serif="" style="color: #0000cc; font-family: Verdana,;">'.$waktu.'</span></span></td></tr>
<tr>
<td colspan="2"><span geneva="" sans-serif="" style="color: black; font-family: Verdana,; font-size: small;">berkata : <i><b>'.$komentar.'</b></i></span></td></tr>
</tbody></table>
<span style="font-size: small;">

<span style="font-size: x-small;">');
for ($i = 0; $i < 999; $i++)
{
fwrite ($fp, $comfile[$i]);
}

fclose ($fp);
if ($_POST['submit']) {
 header ("location: index.php");
}

$file = "jumlah.txt";
$open = fopen($file,"r+");
$counter=fread($open,filesize($file)); 
fclose($open);
$counter++;
$write=fopen($file,'w');
fputs($write,$counter); 
fclose($write);

</span>
</span>

4. Buka Browser anda, lalu panggil alamat tempat anda menyimpan source code Misalnya : localhost/buku_tamu(nama folder anda)

   

0 comments:

Posting Komentar