Home > Pemograman > Contoh Buku Tamu

Contoh Buku Tamu


Sekarang mari kita lihat contoh lainnya, yaitu buku tamu.

Struktur tabel bukutamu di MySQL

CREATE TABLE `bukutamu` (
`nomor` int(10) NOT NULL auto_increment,
`nama` varchar(50) NOT NULL,
`email` varchar(50) NOT NULL,
`waktu` varchar(30) NOT NULL,
`komentar` text NOT NULL,
PRIMARY KEY (`nomor`)
)

bukutamu.php
Buku Tamu

Buku Tamu

Nama:

Email:

Komentar:



<!–?php
//lakukan koneksi ke MySQL
mysql_connect(“localhost”,”root”,””);

//Pilih database tempat tabel akan dibuat
mysql_select_db(“databaseku”);

$data = mysql_query(“SELECT * FROM bukutamu ORDER BY nomor DESC”);
$w = 1;
while($d=mysql_fetch_array($data)){
//buat warna selang-seling
if($w == 1){
$warna = “#ffffff”;
$w = 0;
}else{
$warna = “#efefef”;
$w = 1;
}
echo “

“;
echo “Nama : “.$d['nama'].”
“;
echo “Email : “.$d['email'].”
“;
echo “Waktu : “.$d['waktu'].”
“;
echo “Komentar :
“.$d['komentar'];
echo “

\n”;
}
?>

isibukutamu.php

<!–?php
//lakukan koneksi ke MySQL
mysql_connect(“localhost”,”root”,””);

//Pilih database tempat tabel akan dibuat
mysql_select_db(“databaseku”);

$nama = htmlspecialchars($_POST['nama']);
$email = htmlspecialchars($_POST['email']);
$komentar = htmlspecialchars($_POST['komentar']);
$waktu = date(“H:i d M Y”);
//jika user tekan enter atau barisbaru, kasih tag

$komentar = nl2br($komentar);

$isi = mysql_query(“INSERT INTO bukutamu VALUES(null,’$nama’,’$email’,’$waktu’,’$komentar’)”);
if($isi){
header(“location:bukutamu.php”);
}else{
echo “Gagal”;
}
?>

About these ads
Categories: Pemograman
  1. No comments yet.
  1. No trackbacks yet.

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: