The Making of Guest Book in Web Application Using PHP

Recently, i have just learned about web programming. Actually, there are several items that we must know to build or create a good website. The first is HTML code, the second one is PHP structure. CSS , javascript, jquery and etc.

Alhamdulillah, only in several days, i already finished them.but, even though i think it is already good enough.

first of all, we have to prepare the form. I mean guest book form. And then make file to process data which is already sent named savefile.php.. and the last task is put the file into guest_log.txt”. Here is the first step.


<html>
<head>
<title>Buku Tamu</title>
<script>
function validasi(){
var nama=form.txtnama.value;
var emailregex=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
var email=form.txtemail.value;
if(nama==""){
alert('nama harus diisi');
return false;
}
if(!(email.match(emailregex))){
alert("alamat email tidak valid");
return false;
}
}
</script>
<style>
h1{
background:#FFFFFF;
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:40px;
padding-top:18px;
}
</style>
</head>
<body>
<h1 align="center">Selamat Datang</h1>
<table align="center" border="1" cellpadding="20">
<tr>
<td>
<table border="0" cellpadding="5">
<form method="post" action="save.php" name="form" id="form" >
<tr>
<td align="right">Nama :</td><td><input type="text" name="txtnama" id="txtnama" onBlur="return validasi()"/></td>
</tr>
<tr>
<td align="right">Alamat :</td><td><input type="text" name="txtalamat"/></td>
</tr>
<tr>
<td align="right">E- mail :</td><td><input type="text" name="txtemail" onBlur="return validasi()"/></td>
</tr>
<tr>
<td align="right">Website/ Blog :</td><td><input type="text" name="txtblog"/></td>
</tr>
<tr>
<td align="right">Komentar :</td><td><textarea name="txtkomentar"></textarea></td>
</tr>
<tr>
<td align="right"><input type="submit" value="Save" name="btsave" /></td><td><input type="reset" value="Reset"/></td>
</tr>
</form>
</table>
</td>
</tr>
</table>
</body>
</html>


alright, if you check out in your browser, the preview is almost like this one,it means that you have been sucessfull to make the form, and the next, is to send the form using method post into file save.php.But, before that, we have to make file bukutamu.txt in the same directory of the program.

here is the code for saving data of guests :

<?php
$nama=$_POST['txtnama'];
$alamat=$_POST['txtalamat'];
$email=$_POST['txtemail'];
$blog=$_POST['txtblog'];
$komentar=$_POST['txtkomentar'];
if(empty($nama)){
echo "nama kosong harus diisi";
}
$simpan="Nama = $nama \n alamat=$alamat \n email=$email \n blog=$blog \n komentar = $komentar \n";
$daftartamu="bukutamu.txt";
if(file_exists($daftartamu)){
echo "file is found";
$fo=fopen($daftartamu,'a');
fputs($fo,$simpan,1024);
fclose($fo);
}
else{
echo "file not found";
}
?

Inside the code above, there are several functions for file operation such as fopen, feof, fgets and etc. that’s why in this program doesn’t need database as storage. here is the result of the program :

good luck🙂

 

Tagged: , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: