Вы находитесь на странице: 1из 17

PHP & MySQL

Buku Tamu
Database Buku Tamu
 Database
 BukuTamu
 Tabel
 Anggota
 Field
 ID Int(10)
 Nama VarChar(20)
 Alamar VarChar(40)
 NoTelp VarChar(20)
 Email VarChar(25)
 Komentar Text
Form Buku Tamu
<html>
<body>
<center><h1>
<a href=“Tambah.php">ADD</a>
<br>
<a href=“Lst.php">DAFTAR</a>
<br>
<a href=“Cari.php">SEARCH</a>
</center>
</body>
</html>
Koneksi Buku Tamu
<?
$server = "localhost";
$username = "root";
$password = "";
$database = "bukutamu";

mysql_connect($server,$username,$password) or
die ("Koneksi Gagal");
mysql_select_db($database) or die ("Database Tidak
Bisa di buka");
?>
Tambah Buku Tamu
Coding Tambah Buku Tamu (1)
<?
include "KoneksiBukuTamu.php";

if($_POST['action'])
{
$Name=$_POST['Nama'];
$Alamat=$_POST['Alamat'];
$NoTelp=$_POST['NoTelp'];
$Email=$_POST['Email'];
$Komentar=$_POST['Komentar'];
Coding Tambah Buku Tamu (2)
$query="INSERT INTO anggota (ID, Nama, Alamat, NoTelp,
Email, Komentar) VALUES (NULL, '$Nama', '$Alamat',
'$NoTelp', '$Email', '$Komentar')";
$rez=mysql_query($query);
}
?>
Coding Tambah Buku Tamu (3)
<form action="<? echo $_SERVER['localhost'] ?>" method="post">
Nama<br><input type="text" name="Nama"><br />
Alamat<br><input type="text" name="Alamat"><br />
NoTelp<br><input type="text" name="NoTelp"><br />
Email<br><input type="text" name="Email"><br />
Komentar<br><textarea cols = 15 rows = 5
name="Komentar"></textarea><br />
<br><input type="submit" name="action" value="Simpan">
</form>

<a href="List.php">List</a>
<br>
<a href="Cari.php">Search</a>
List Buku Tamu
Coding List Buku Tamu (1)
<table border = 4>
<tr>
<th>ID</th>
<th>Nama</th>
<th>Alamat</th>
<th>NoTelp</th>
<th>Email</th>
<th>Komentar</th>
</tr>
Coding List Buku Tamu (2)
<?
include "KoneksiBukuTamu.php";
$query="SELECT * FROM anggota";
$rez=mysql_query($query);
while ($row = mysql_fetch_array($rez))
{
print "<tr>
<td>{$row['ID']}</td><td>{$row['Nama']}</td>
<td>{$row['Alamat']}</td><td>{$row['NoTelp']}</td>
<td>{$row['Email']}</td><td>{$row['Komentar']}</td></tr>";
}
?>
Coding List Buku Tamu(3)
</table>
<a href="Cari.php">Search</a>
<a href="Tambah.php">Tambah</a>
Cari Buku Tamu
Coding Cari Buku Tamu (1)
<?
include "KoneksiBukuTamu.php";
if($_POST['action'])

{
$key=$_POST['key'];
$query = "SELECT * FROM anggota WHERE name LIKE
'%$key%' OR surname LIKE '%$key%' ";
$result = mysql_query($query);
Coding Cari Buku Tamu (2)
print "<table border = 4>
<tr> <th>ID</th><th>Nama</th>
<th>Alamat</th><th>NoTelp</th>
<th>Email</th><th>Komentar</th></tr>";
while ($row = mysql_fetch_array($result))
{
print "<tr>
<td>{$row['ID']}</td><td>{$row['Nama']}</td>
<td>{$row['Alamat']}</td><td>{$row['NoTelp']}</td>
<td>{$row['Email']}</td><td>{$row['Komentar']}</td></tr>";
}
}
print "</table>";
?>
Coding Cari Buku Tamu (3)
<form action="<?php echo $_SERVER[‘localhost'] ?>"
method="post">

Nama :
<br><input type="text" name="key"><br />
<br><input type="submit" name="action" value="Cari">
</form>