Rabu, 15 Juni 2011

Membuat Buku Tamu


Bisa Menggunakan SQLYog  Enterprise dan bisa menggunakan server wamp atau xampp.


Membuat buku tamu
  1. buat database dengan nama “dataku” di SQLYog Enterprise
  2. buat tabel dengan nama “bukutamu” dengan struktur sbb:
Field
Type
Length/value
Atribute
Null
Default
extra
Nama
Varchar
35

Not null


Email
Varchar
40

Not null


Komentar
Text


Not null


Tanggal
Varchar
25

Not null



Listing program :
1. db.php

<?
$db_hostname="localhost";
$db_username="root";
$db_password="";
$db_name="dataku";
function connect_db()
{
global
$db_hostname,$db_username,$db_password,$db_name;
mysql_connect($db_hostname,$db_username,$db_password);
mysql_select_db($db_name);
}
?>

2. link.php

<html>
<head>
<title>Buku Tamu</title>
</head>
<body>
<form name="form1" method="post" action="">
  <p>
    <input name="imageField" type="image" src="file:///C|/apache/htdocs/ZakatOL/IMGSP.JPG" width="1200" height="120" border="0">
</p>
  <table width="430" border="0" align="center">
    <tr>
      <td width="68"><a href="home.php">[ Home ] </a> </td>
      <td width="112"><a href="bukutamu_form.php">[ Isi Buku tamu ] </a></td>
      <td width="140"><a href="bukutamu_list.php">[ Lihat Buku Tamu ] </a></td>
      <td width="80">[ About ] </td>
    </tr>
  </table>
</form>
</body>
</html>

3. bukutamu_form.php
<html>
      <head>
                  <title>Buku Tamu PHP dan MySQL</title>
</head>
<?
include_once("link.php");?>
<body>
            <h2>&nbsp; </h2>
                  <h2>Formulir buku tamu</h2>
                  <hr>
                  <form method="post" action="bukutamu_saving.php?save=ok">
                  <table width="494" border="0" cellpadding="0" cellspacing="0">
                  <tr>
                              <td width="78">nama </td>
                              <td>:&nbsp;<input name="nama" type="text" size="25" maxlength="50"></td>
                              <td width="406"></td>
                  </tr>
                  <tr>
                              <td>email</td>
                              <td>:&nbsp;<input name="email" type="text" size="25" maxlength="50"></td>
                              <td>&nbsp;</td>
                  </tr>
                  <tr>
                              <td>komentar </td>
                              <td rowspan="3">&nbsp;&nbsp;<textarea name="komentar" cols="27" rows="5"></textarea></td>
                  </tr>
                  <tr>
                    <td>&nbsp;</td>
                    </tr>
                  <tr>
                    <td>&nbsp;</td>
                    </tr>
                  <tr>
                              <td><input type="submit" name="submit" value="kirim"></td> <td><input type="reset" name="reset" value="batal"></td>
                              <td>&nbsp;</td>
                              <td>&nbsp;</td>
                  </tr>
                  </table>
                  <hr>
                  </form>
                  </body>
                  </html>

4. bukutamu_saving.php
<?
include_once("link.php");
include_once("db.php");
$tanggal=date("d M Y H:m:s");
if($save=="ok"){
      connect_db();
      $sqlstr="INSERT INTO booktamu(tanggal,nama,email,komentar)
                  values('$tanggal','$nama','$email','komentar')";
                  $hasil=mysql_db_query($db_name,$sqlstr);
      if ($hasil){
                  echo "<b> inilah data-data yang tadi anda simpan:</b>";
                  echo "<br>";
                  echo "<hr>";
                  echo "$tanggal";
                  echo "<br>";
                  echo "nama : $nama";
                  echo "<br>";
                  echo "email: $email";
                  echo "<br>";
                  echo "komentar: $komentar";
                  echo "<hr>";
                  echo "data berhasil disimpan ke database!";
      }else {
                  echo "data gagal disimpan ke database!";
                  }
      }
?>
<a href="bukutamu_list.php">Lihat Buku tamu</a>

5. bukutamu_list.php
<html>
      <head>
      <?
      include_once("link.php");?>
      <title>daftar buku tamu</title></head>
      <body>
      <h2>daftar buku tamu pada database kami:</h2>
      <hr>
      <?
     
                  include_once("db.php");
                  connect_db();
                  $sqlstr="SELECT*FROM bukutamu";
                  $hasil=mysql_db_query($db_name,$sqlstr);
                  $row=mysql_fetch_row($hasil);
                  if($row){
                              do{
                                          list($tanggal,$nama,$email,$komentar)=$row;
                                          echo "disimpan pada tanggal:$tanggal";
                                          echo "<br>";
                                          echo "<b> nama:</b> $nama";
                                          echo "<br>";
                                          echo "<b>email:</b> $email";
                                          echo "<br>";
                                          echo "<b> komentar</b>$komentar";
                                          echo "<hr>";                           
                  }while($row=mysql_fetch_row($hasil));
                  }else{
                              echo "maaf, belum ada tamu!!";}
      ?>
      <a href="bukutamu_form.php">isi buku tamu lagi</a>
      </body>
      </html>

 Lalu buka file "bukutamu_form.php" di web browser (mozilla firefox, google chrome, IE, dll). Janganlupa aktifkan wamp server atau Xampp server Anda.
                             

Tidak ada komentar:

Posting Komentar