Home » » Membuat Guestbook Dengan PHP Dan Database

Membuat Guestbook Dengan PHP Dan Database

Written By Hisyam Yahya on Thursday, 19 April 2012 | 9:47:00 am



Hy semua sudah lama aku tidak pernah posting maaf ada banyak hal yang harus dikerjain.
ok hari ini kita akan membahasa bagaimana cara membuat Guestbook dengan php dan database.
Berikut ini adalah file-file yang akan kita buat ...
1. Buat database dan table di database.
2. Buat config.php
3. Script Security.php
3. Script index.html
4. Script save.php
5. Script view.php
===================================
1.  kita buat database buat database terserah kalian buat nama apa.
===================================
 Setelah buat database
buat table seperti dibawah ini:
CREATE TABLE `guestbook` (
  `id` int(11) NOT NULL auto_increment,
  `nama` varchar(90) character set latin1 collate latin1_general_ci NOT NULL,
  `email` varchar(60) character set latin1 collate latin1_general_ci NOT NULL,
  `url` varchar(100) character set latin1 collate latin1_general_ci NOT NULL,
  `alamat` varchar(70) character set latin1 collate latin1_general_ci NOT NULL,
  `komentar` varchar(255) character set latin1 collate latin1_general_ci NOT NULL,
  `time` varchar(30) character set latin1 collate latin1_general_ci default NULL,
  `date` varchar(30) character set latin1 collate latin1_general_ci default NULL,
  `ip` varchar(30) character set latin1 collate latin1_general_ci default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=19 ;
===================================
2. Buat file baru dengan nama (Config.php)
===================================

<?php
mysql_connect("$db_host","$db_user","$db_pass");
mysql_select_db("$db_name");
?>
===================================
3. Buat file baru dengan nama (index.html)
===================================
<?php
session_start();
class CaptchaSecurityImages {
var $font = 'monofont.ttf';
function generateCode($characters) {
/* list all possible characters, similar looking characters and vowels have been removed */
$possible = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; 
$code = '';
$i = 0;
while ($i < $characters) { 
$code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
$i++;
}
return $code;
}
function CaptchaSecurityImages($width='120',$height='40',$characters='6') {
$code = $this->generateCode($characters);
/* font size will be 75% of the image height */
$font_size = $height * 0.75;
$image = @imagecreate($width, $height) or die('Cannot Initialize new GD image stream');
/* set the colours */
$background_color = imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image, 50, 10, 175);
$noise_color = imagecolorallocate($image, 200, 150, 100);
/* generate random dots in background */
for( $i=0; $i<($width*$height)/3; $i++ ) {
imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
}
/* generate random lines in background */
for( $i=0; $i<($width*$height)/150; $i++ ) {
imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
}
/* create textbox and add text */
$textbox = imagettfbbox($font_size, 0, $this->font, $code);
$x = ($width - $textbox[4])/2;
$y = ($height - $textbox[5])/2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code);
/* output captcha image to browser */
imagejpeg($image);
imagedestroy($image);
$_SESSION['security_code'] = $code;
}
}
$width = isset($_GET['width']) ? $_GET['width'] : '120';
$height = isset($_GET['height']) ? $_GET['height'] : '40';
$characters = isset($_GET['characters']) ? $_GET['characters'] : '6';
header('Content-Type: image/jpeg');
$captcha = new captchasecurityimages($width,$height,$characters);
?>
===================================
4. Buat file baru dengan nama (index.html)
===================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Guestbook</title>
</head>

<body>
<div align="justify"></div>
<form name="form1" method="post" action="save.php">
<pre>
<table border="0">
<tr>
<th align="right" valign="top">Nama</th>
<th align="right" valign="top">:</th>
<td valign="top"><input name="nama" type="text" id="nama" size="35"/></td></tr>
<tr><th align="right" valign="top">Email</th>
<th align="right" valign="top">:</th>
<td valign="top"><input name="email" type="text" size="35"/></td></tr>
<tr><th align="right" valign="top">Website</th>
<th align="right" valign="top">:</th>
<td valign="top"><input name="url" type="text" size="35"/></td></tr>
<tr><th align="right" valign="top">Alamat</th>
<th align="right" valign="top">:</th>
<td><input name="alamat" type="text" size="35"/></td></tr>
<tr><th align="right" valign="top">Isi</th>
<th align="right" valign="top">:</th>
<td valign="top"><textarea name="komentar" rows="5" cols="40"/></textarea></td></tr><tr><th align="right" valign="top">Secrutiy</th><th align="right" valign="top">:</th><td valign="top"><img src="security.php?width=100&height=40&character=5"><br /><input id="security_code" name="security_code" type="text" /></td></tr><tr><th align="right" valign="top">&nbsp;</th><th align="right" valign="top">&nbsp;</th><td valign="top"><input type="submit" name="submit" value="Submit" /><input type="reset" name="Reset" value="Reset" /></td></tr></table></pre>
</form>

</body>
</html>
===================================
5. Buat file baru dengan nama (Save.php)
===================================
<?php 
session_start();
 require 'config.php';
if( isset($_POST['submit'])) {
   if(($_SESSION['security_code'] == $_POST['security_code']) && (!empty($_SESSION['security_code'])) ) {
$nama = $_POST['nama'];
$email = $_POST['email'];
$url = $_POST['url'];
$alamat = $_POST['alamat'];
$komentar = $_POST['komentar'];
$time = date("H:i:s");
$date = date ("d/m/Y");
$ip = $_SERVER['REMOTE_ADDR'];

$sql ="INSERT INTO guestbook (nama,email,url,alamat,komentar,time,date,ip) VALUES('$nama','$email','$url','$alamat','$komentar','$time','$date','$ip')";
mysql_query($sql);
echo"<h2>Pesan Berhasil Dikirim</h2><br />
 <a href= viewmsg.php>Klik Disini</a> Untuk Melihat pesan Yang Sudah Dikirim";
      include "index.php";

  } else {
      // Insert your code for showing an error message here
      echo '<h2>Maaf Code Secruity Yang Anda Masukkan Salah Silahkan Coba Lagi</h2>';
      include "index.php";
   }
} else {

      include "index.php";

    }
?>
===================================
6. Buat file baru dengan nama  (View.php)
===================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body bgcolor="#66FF00">
<table  align="center" cellspacing="1" border="1">
  <tr>
    <th colspan="2"><span class="hisyam" ><font color="#ff0000">*</font><font color="#ff3300">*</font><font color="#ff6600">*</font><font color="#ff9900">.</font><font color="#ffcc00">:</font>M<font color="#ccff00">Y</font> <font color="#66ff00">G</font><font color="#00ff00">U</font><font color="#00ff33">E</font><font color="#00ffff">S</font><font color="#00ccff">T</font><font color="#0099ff">B</font><font color="#0066ff">O</font><font color="#ff0000">OK </font><font color="#00ccff">:</font><font color="#0099ff">.</font><font color="#0066ff">*<font color="#ff0000">*</font><font color="#ff3300">*</font> </font></span></th>
  </tr>
  <tr>
    <th  width="350"><center>
        <font size="4"><font color="#ffcc00">P</font>e<font color="#ccff00">n</font><font color="#99ff00">g</font><font color="#00ffff">i</font><font color="#00ccff">r</font><font color="#0099ff">i</font><font color="#ffcc00">m</font><font color="#ffff00"> :</font></font>
    </center></th>
    <th  width="350"><center>
        <font size="4"><font color="lime">C</font><font color="#ccff00">o</font><font color="#99ff00">m</font><font color="#66ff00">m</font><font color="#00ff00">e</font><font color="#00ff33">m</font><font color="#00ffff">e</font><font color="#00ccff">n</font><font color="#0099ff">t</font><font color="#0066ff"> :</font></font>
    </center></th>
  </tr>
<?
require 'config.php';
$yahya = " SELECT * FROM guestbook ORDER BY ID DESC";
$karya = mysql_query($yahya);
while ($hisyam =  mysql_fetch_array($karya)) { 

echo "
<tr > 
      <td valign='top' align='left'><font size='2'><img src='../images/buku.gif' style='border:0;margin:0;' >&nbsp;Nama:&nbsp;<b><a href='$hisyam[url]'>$hisyam[nama]</a></b><br>
    <img src='../images/inbox.gif'  style='border:0;margin:0;' >&nbsp;Email :&nbsp;<a href='mailto:$hisyam[email]'>$hisyam[email]</a> <br>
    &nbsp;Website :&nbsp;<a href='$hisyam[url]'>$hisyam[url]</a>
    <br />&nbsp;Lokasi :&nbsp; $hisyam[alamat]<br>
    <img src='../images/ip.gif' style='border:0;margin:0;'  >$hisyam[ip]<br></td>
      <td valign='top' align='left'><font size='2'><img src='../images/post.gif' style='border:0;margin:0;' > $hisyam[date], $hisyam[time]<br>
<hr color='#FF6600' style='border: dashed 1px;'>
$hisyam[komentar]</td>";  }  ?>
</table>
</body>
</html>

Jika Sudah simapn dan lihat hasil semoga sukses ..?
Download Scriptnya  Disini
Password MEDIAFIRE : his4myahya.blogspot.com
Share this article :

12 comments :

  1. Hello There. I found your blog using msn. This is an extremely well written article.
    I'll be sure to bookmark it and return to read more of your useful information. Thanks for the post. I will definitely return.
    Check out my blog post DubLi Network - Top Internet Business Modell

    ReplyDelete
  2. I have been browsing online more than 2 hours today, yet I never found any
    interesting article like yours. It is pretty worth enough for me.
    Personally, if all website owners and bloggers made good content as
    you did, the internet will be much more useful than
    ever before.
    Here is my blog post : Camille Chidiac page

    ReplyDelete
  3. Hey There. I found your blog the usage of msn. That is a really well
    written article. I will be sure to bookmark it and return to learn more of your useful information.
    Thanks for the post. I will certainly comeback.
    Here is my web-site ... [American Coins|Buy American Coins|American Coins For Sale|Gold Coins|Silver Coins}

    ReplyDelete
  4. @Anonymousthank you friend me if this article was helpful for you I'll make another more interesting articles

    ReplyDelete
  5. @Anonymousthank you friend me if this article was helpful for you I'll make another more interesting articles

    ReplyDelete
  6. @Anonymousthank you friend me if this article was helpful for you I'll make another more interesting articles

    ReplyDelete
  7. This comment has been removed by a blog administrator.

    ReplyDelete
  8. http://paydayloansen.com/ loan payday , loan payday , [url=http://paydayloansen.com]loan payday

    ReplyDelete
  9. http://paydayloansen.com/payday loans in las vegas nevada , payday loans in las vegas nevada , [url=http://paydayloansen.com]payday loans in las vegas nevada

    ReplyDelete
  10. This comment has been removed by a blog administrator.

    ReplyDelete
  11. his4myahya.blogspot.com is well done, but loads very slow

    [url=http://gonorrheatreatment.blogspot.com]gonorrhea pictures
    [/url]

    ReplyDelete

 
Support : Your Link | Your Link | Your Link
Copyright © 2013. hisyam yahya - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger