22
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


22 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

Anonim mengatakan... [Reply to comment]

Wonderful blog! I found it while searching on Yahoo News. Do you have
any suggestions on how to get listed in Yahoo
News? I've been trying for a while but I never seem to get there! Thanks

Here is my webpage: Oakley Frogskins

Anonim mengatakan... [Reply to comment]

Right now it appears like Movable Type is the best blogging platform available right now.
(from what I've read) Is that what you're using on your
blog?

Here is my weblog; tedxyse.com

Anonim mengatakan... [Reply to comment]

I seldom write responses, however after reading a few of the responses on this page "Membuat Buku Tamu dengan Menggunakan PHP dan MySQL".
I actually do have some questions for you if it's allright. Is it just me or do some of these remarks look like they are coming from brain dead visitors? :-P And, if you are posting on additional sites, I'd like to keep up with you.
Could you list of all of all your social sites like your twitter feed, Facebook
page or linkedin profile?

Visit my website NFL Jerseys Cheap

Anonim mengatakan... [Reply to comment]

It's an amazing post for all the web visitors; they will take benefit from it I am sure.

my website Abercrombie and Fitch

Anonim mengatakan... [Reply to comment]

I don't even understand how I finished up right here, however I thought this publish used to be good. I don't know who you
are however definitely you're going to a famous blogger if you are not already. Cheers!

Feel free to visit my web blog :: ngosummit.com

Anonim mengatakan... [Reply to comment]

I do not even know how I stopped up here, but I thought this post was good.
I don't realize who you are however certainly you're
going to a famous blogger should you are not already.
Cheers!

Here is my weblog - Abercrombie Pas Cher ()

Anonim mengatakan... [Reply to comment]

I constantly spent my half an hour to read this webpage's articles daily along with a mug of coffee.

My site Nike Free 7.0

Anonim mengatakan... [Reply to comment]

Terrific article! That is the kind of info that are supposed to be shared around
the net. Disgrace on Google for not positioning this submit upper!
Come on over and seek advice from my website . Thank you =)

Feel free to surf to my webpage - Sac Louis Vuitton

Anonim mengatakan... [Reply to comment]

If some one desires expert view about running a blog then i recommend him/her to pay a visit this weblog, Keep up
the nice work.

Also visit my web blog :: Cheap NFL Jerseys

Anonim mengatakan... [Reply to comment]

Hi, just wanted to tell you, I enjoyed this blog post.
It was practical. Keep on posting!

My site - Michael Kors **

Anonim mengatakan... [Reply to comment]

Hello, Neat post. There is a problem along with your site in web explorer,
could check this? IE still is the marketplace leader and a big part of folks will leave out your great
writing because of this problem.

Here is my website: Soldes Air Jordan

Posting Komentar

Silahkan tinggalkan komentar anda disini...

 
Ujie Caprone | © 2011 Blogger Template by Ujiecaprone.com