STMIK DHARMAPALA RIAU

Sekolah Tinggi Management Informatika Dan Komputer

Contoh Buku Tamu

nah sekarang mari kita praktekan gimana cara membuat bku tamu online..  ;)

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

<html>

<head><title>Buku Tamu</title></head>

<body>

<font face=arial size=2>

<h2>Buku Tamu</h2>

<form action=”isibukutamu.php” method=”post”>

Nama:<br>

<input type=”text” name=”nama”><p>

Email:<br>

<input type=”text” name=”email”><p>

Komentar:<br>

<textarea name=”komentar” cols=40 rows=10></textarea>

<p><input type=”submit” value=”Kirim”>

</form>

<hr>

<!—kode PHP untuk menampilkan bukutamu——->

<?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 “<div style=\”background-color:$warna;padding:5\”>”;

echo “Nama : “.$d['nama'].”<br>”;

echo “Email : “.$d['email'].”<br>”;

echo “<font size=1>Waktu : “.$d['waktu'].”</font><br>”;

echo “<b>Komentar :</b><br>”.$d['komentar'];

echo “</div><p>\n”;

}

?>

</font>

</body>

</html>

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 <br>

$komentar = nl2br($komentar);

$isi = mysql_query(“INSERT INTO bukutamu VALUES(null,’$nama’,’$email’,’$waktu’,’$komentar’)”);

if($isi){

header(“location:bukutamu.php”);

}else{

echo “Gagal”;

}

?>

hmm klo berhasil share kesini ya.. dan klo blm berhasil nanya kesini tak coba bantuin heheh..  ;)

About these ads

Filed under: My SQL, Pemograman, PHP, Tips and Trik, Website

One Response

  1. [...] buat form buku tamu menggunakan PHP..  untuk sekedar latihan  hehehhe… selanjutnya>> Contoh Buku Tamu Share this:TwitterFacebookLike this:SukaBe the first to like this [...]

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

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 6 other followers

Follow Twitter

Error: Twitter did not respond. Please wait a few minutes and refresh this page.

%d bloggers like this: