Prodi Sistem Informasi | Belajar HTML dan PHP | Skripsi SI
Pesantren Katabah
1000 Penghafal Quran
Pengobatan Ruqyah Mandiri
Sistem Informasi (S1)
Manajemen Informatika
Blog | Kontak | Siap Kerja | Sertifikat | PrivacyPolicy | Inggris Arab | Daftar Isi

Friday, January 17, 2014

Membuat Buku Tamu Dengan PHP



1.      Software:
·         WampServer 2.2
·         Apache 2.2.21
·         PHP 5.3.10
·         MySQL 5.5.20
2.      Buat database: ikhbaar
3.      Buat tabel: bukutamu

Column
Type
Length
nama
Varchar
75
pesan
Text


4.      Buat file: tampil.php
Ketik script berikut:
<html>
<head>
<title>Tutorial Buku Tamu</title>
</head>
<?php
$id_massage = isset($_GET["id_massage"]) ? $_GET["id_massage"] : "";

switch($id_massage)
     {
     case 1:
                 $tls_pesan = "Isikan seluruh masukkan data dengan benar";
                 break;

     case 2:
                 $tls_pesan = "Data Berhasil Dimasukkan";
                 break;
     case 3:
                 $tls_pesan = "Data Gagal dimasukkan";
                 break;
     default:
                 $tls_pesan = "";
                 break;
     }
?>


<body>
<table width="310" border="1" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="306"><table width="298" border="1" cellspacing="0" cellpadding="0">
      <tr>
        <td width="294"><p align="center">Belajar Membuat Buku Tamu Dengan PHP </p>
          <p align="center"><a href="http://info-webprogram.blogspot.com">http://info-webprogram.blogspot.com </a> </p>          <Header></td>
      </tr>
      <tr>
        <td><form action="proses.php" method="post" name="guest book" id="guest book">
          <table width="85%"  border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
              <td width="25%">&nbsp;</td>
              <td width="75%">&nbsp;</td>
            </tr>
            <tr>
              <td>Nama</td>
              <td><input name="nama" type="text" id="nama" size="25" maxlength="75"></td>
            </tr>      
            <tr>
              <td>Pesan</td>
              <td><textarea name="pesan" cols="35" rows="7" id="pesan"></textarea></td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td><?php echo $tls_pesan?></td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td><input name="submit" type="submit" id="submit" value="Submit">
                <input name="reset" type="reset" id="reset" value="Reset"></td>
            </tr>
          </table>
        </form>
<?php
$db_host = "localhost";
$db_user = "root";
$db_password = "";
$db_name = "ikhbaar";

$conn_db = @mysql_connect($db_host, $db_user, $db_password) or die("Settingan database server salah");
$select_db = @mysql_select_db($db_name) or die("Database tidak diketemukan");
$query = "SELECT * FROM bukutamu";
$result = mysql_query($query);
while ($data = mysql_fetch_array($result))
     {
     $tls_nama = $data["nama"];
     $tls_catatan = $data["pesan"];
    
     echo "<table width='85%' cellpadding='4' cellspacing='1' align='center' bgcolor='#000000'>";

     echo "<tr><td bgcolor='#EEEEEE'> $tls_nama ::<br>";
     echo "<tr><td bgcolor='#F5F5F5'>$tls_catatan <br></td></tr></table><br />";
     }

mysql_close($conn_db);
?>
                
                 </td>
      </tr>
      <tr>
        <td align="center"><span class="style2">Sumber: Abdul Hanan. Belajar PHP. Hal 31, file: belajar_php.pdf </span></td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>

5.       Buat file: proses.php
Ketik script berikut:
<?php
$db_host = "localhost";
$db_user = "root";
$db_password = "";
$db_name = "ikhbaar";

$conn_db = mysql_connect($db_host, $db_user, $db_password) or die("settingan database server salah");
$select_db = mysql_select_db($db_name) or die("Database tidak diketemukan");

$nama = $_POST["nama"];
$catatan = $_POST["pesan"];
if (!$nama || !$catatan)
{
header("location: tampil.php?id_massage=1");
exit;
}

$query = "INSERT INTO bukutamu (nama, pesan)
VALUES ('$nama', '$catatan')";
$result = mysql_query($query);
mysql_close($conn_db);
if ($result)
{
header("location: tampil.php?id_massage=2");
exit;
}
else
{
header("location: tampil.php?id_massage=3");
exit;
}
?>
  

6.      Hasilnya:


Catatan:
·         Tulisan Komar Tamu 1 dan Tasdik Tamu 2 pada Gambar langkah 6 akan muncul setelah sahabat mengentri nama dan pesan di kotak yang sudah tersedia.
.

***
Sumber: Abdul Hanan. Belajar PHP. Hal 31, file: belajar_php.pdf
"Boleh Konsultasi Masuk Jurusan Sistem Informasi via IG atau Tiktok."
Tips Skripsi Program Studi Sistem Informasi

No comments:

Post a Comment