11
Membuat Buku Tamu dengan Menggunakan PHP dan MySQL

Guest book atau buku tamu memang merupakan salah satu tool situs yang sifatnya interatif. Jika situs Anda dilengkapi dengan guest book, maka pengunjung bisa meninggalkan pesan yang bisa Anda baca dan juga bisa dibaca pula oleh orang lain.

Persiapan
Untuk membuat guest book kali ini, maka di komputer Anda harus sudah ada beberapa tool yang bisa digunakan, seperti:

* Web server, di sini penulis menggunakan Apache web server versi 1.3.33 (win32)
* PHP, di sini penulis menggunakan PHP versi 4.3.11 (win32)
* Database, di sini penulis menggunakan MySQL database versi 4.1.11-nt-max (win32)

Pastikan semua service sudah jalan, seperti service web server dan juga mysql. Untuk menjalankan service Apache, Anda bisa ketikkan net start apache. Untuk menjalankan service MySQL, maka Anda bisa mengetikkan net start mysql.

Setelah itu Anda harus membuat database dan tabel di dalam MySQL yang berfungsi sebagai tempat menyimpan data dari guest book nantinya. Di sini penulis membuat database yang bernama coba dan nama tabelnya adalah gbook. Berikut ini adalah script untuk membuat tabelnya.


create table gbook (

tanggal date,

nama varchar(255),

email varchar(255),

pesan text);



Kita lihat pada tabel gbook tersebut akan terdiri field tanggal untuk menyimpan tanggal posting, nama untuk menyimpan nama pengunjung, email untuk menyimpan data email dan pesan untuk menyimpan kesan dan pesan dari pengunjung.


Pembuatan

Hanya ada dua file yang dibutuhkan dalam misi ini, yaitu file HTML form nya dan script pemroses data form-nya. Untuk HTML form nya, penulis beri nama guest_book.php dan script pemrosesan data guest booknya, penulis beri nama gbook_p.php.


Berikut code untuk file PHPnya


<?php

include “config.php”; // digunakan untuk memasukkan kode dari file lain yang ditunjuk


// proses penambahan data ke database

if($mod == “add”){


$add_query = mysql_query(”insert into bukutamu values(”, ‘$nama’, ‘$email’, ‘$alamat’, ‘$pesan’)”) or die(mysql_error());

}

?>


<html>

<head>

<title>Belajar membuat buku tamu</title>

</head>

<body>


<?php

if($add_query){

echo “Isian berhasil di tambahkan, <a href=\”lihat.php\”>lihat data buku tamu</a>”;

}else{

?>

Form Buku Tamu <br /><br />


<form method = “post” action = “#”>

nama : <input type = “text” name = “nama”><br>

email : <input type = “text” name = “email”><br>

alamat : <textarea name=”alamat”></textarea><br>

pesan : <textarea name=”pesan”></textarea><br>


<input type=”hidden” name=”mod” value=”add”>

<input type=”submit” name=”button” id=”button” value=”Submit”>

</form>

<?php

}

?>

</body>

</html>


Setelah selesai membuat kode PHPnya sekarang kita akan membuat koneksi databasenya, berikut scriptnya :



<?php

$hostDB = “localhost”; // untuk hostname database, disesuaikan dengan server

$userDB = “root”; // secara default, XAMPP membuat database user root

$passDB = “”; // secara default, password root adalah null

$DB = “belajar”; // sesuaikan dengan database yang dibuat


// memulai koneksi ke database

$conn = mysql_connect ($hostDB, $userDB, $passDB) or die(mysql_error());



// seleksi database yang akan digunakan

mysql_select_db($DB, $conn) or die(mysql_error());

?>


Anda harus menyesuaikan nilai-nilai pada variabel di atas dengan keadaan pada server MySQL Anda.


Letakkan semua file tersebut di dalam folder web root Anda dan kemudian Anda bisa panggil file guest_book.php dari web browser.


Bookmark and Share


11 komentar:

komentar mengatakan... [Reply to comment]

asik

Anonim mengatakan... [Reply to comment]

vimax review, buy vimax, buy vimax

Anonim mengatakan... [Reply to comment]

Thus this vicious circle feeds away from itself inside a never-ending merry-go-round
instant payday loans tenants and non home owners would
be the most benefited ones within this lot.

Anonim mengatakan... [Reply to comment]

There might be no reason to wrestle until finally your following paycheck
just visit and apply today moocowpaydayloans.Co.uk an applicant will not likely have the ability to proceed on the next thing if no info is supplied in almost any mandatory field.

Anonim mengatakan... [Reply to comment]

When are applying unapproved renovations in your home, it's possible which it will threaten your house loan, the one you have now and then for any refinancing you hope to perform in the future uk payday loans several california house loan mortgage refinance companies provide following deals: no origination points and hidden costs, confidentiality of purchase, and convenience.

Anonim mengatakan... [Reply to comment]

But as those destinations hit capacitance, that can be won on any secret plan, with any post at any clock time - whole at random! [url=http://www.onlinecasinoburger.co.uk/]online casino[/url] online casino And think of, every fourth dimension you play gorilla top dog 2 this time, don't Use up deal because - you Have got null to mislay and everything to benefit! http://www.onlinecasinotaste.co.uk/

Anonim mengatakan... [Reply to comment]

Hermes BeltsHandbags Hermes cnxr Hermes Handbags2013 Hermes Handbags rcec

Anonim mengatakan... [Reply to comment]

It's very effortless to find out any matter on web as compared to textbooks, as I found this article at this web site.

My web blog; Mario Lemieux Authentic Jersey

Anonim mengatakan... [Reply to comment]

We're a group of volunteers and starting a new scheme in our community. Your site provided us with helpful info to work on. You have done an impressive process and our entire neighborhood will likely be thankful to you.

Visit my blog :: Michael Kors

Anonim mengatakan... [Reply to comment]

Paragraph writing is also a fun, if you be acquainted with after that you can write or else it is complex to write.


Here is my website; Louis Vuitton Bags

Anonim mengatakan... [Reply to comment]

Wow, marvelous weblog structure! How long have you ever been blogging for?
you made running a blog look easy. The entire look of your site is
excellent, let alone the content!

Feel free to surf to my weblog Wholesale Jerseys Cheap

Poskan Komentar

Silahkan tinggalkan komentar anda disini...

 
Ujie Caprone | © 2011 Blogger Template by Ujiecaprone.com