Anda di halaman 1dari 4

Bukutamu.php <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.

dtd"> <html> <head> <title>Buku Tamu</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <form method="post" action="simpanbukutamu.php"> <table width="500" align="center" border="0"> <tr> <td width="130">Nama</td> <td width="5" align="center">:</td> <td width="443"><input name="nama" type="text"></td> </tr> <tr> <td>URL</td> <td align="center">:</td> <td><input name="url" type="text"><sub>*isi dengan alamat web/email anda</sub></td> </tr> <tr> <td valign="top">Komentar</td> <td align="center" valign="top">:</td> <td><textarea name="komentar" cols="30" rows="5"></textarea></td> </tr> <tr> <td>&nbsp;</td> <td>&nbsp;</td> <td><input name="submit" type="submit" value="Post"> <input name="Reset" type="reset" value="Reset"></td> </tr> </table> </form> </body> </html> Simpanbukutamu.php <? $nm=$_POST['nama']; $url=$_POST['url']; $kom=$_POST['komentar']; $tgl=date('j F Y'); include ('librari\koneksi.php'); if ($nm==""){ $nm="Anonymous"; } if (!empty($url) and !empty($kom)){

$query=mysql_query("insert into bukutamu value('','$nm','$url','$kom','$tgl')",$con) or die(mysql_error()); //redirect ke gb.php echo "<meta http-equiv='refresh' content='0; url=gb.php'>"; exit; }else{ echo "<center>Komentar dan URL tidak boleh kosong!</center>"; include "gb.php"; } ?> Tampilbuku.php <html> <head> <title>Bukutamu</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <table width="500" border="0" align="center"> <tr> <td colspan="2" height="50">Buku Tamu<br> <hr noshade> </td> </tr> <? include ('librari\koneksi.php'); $qtotal=mysql_query("select * from bukutamu",$con) or die(mysql_error()); $total=mysql_num_rows($qtotal); // Langkah 1 tentukan batas, cek halaman & posisi data $batas = 4; $halaman = $_GET['halaman']; if (empty ($halaman)){ $posisi = 0; $halaman = 1; } else { $posisi = ($halaman - 1) * $batas; } $query=mysql_query("select * from bukutamu order by 'id' desc limit $posisi,$batas",$con) or die ("Query gagal! ".mysql_error()); while ($row=mysql_fetch_array($query)) { ?> <tr> <td width="130"><a href="http://<? echo $row['url']; ?>"><? echo $row['nama']; ?></a></td> <td>berkomentar..</td> </tr> <tr> <td height="30">&nbsp;</td>

<td valign="top"><? echo $row['komentar']; ?></td> </tr> <tr> <td height="30" valign="bottom">Pada Tanggal :</td> <td valign="bottom"><? echo $row['tanggal']; ?></td> </tr> <tr> <td colspan="3"><hr size="1" color="#000000" noshade></td> </tr> <? } ?> </table> <table width="500" border="0" align="center"> <tr> <td colspan="3" align="center"> <? // Langkah 3 hitung total data dan halaman $tampil2 = mysql_query("select * from bukutamu"); $jmlData = mysql_num_rows($tampil2); $jmlHal = ceil($jmlData/$batas); //Link ke halaman sebelumnya (Prev) if ($halaman > 1){ $prev = $halaman - 1; echo "<a href=$_SERVER[PHP_SELF]?halaman=$prev><< Prev </a>"; }else{ echo "<< Prev |"; } //Tampilkan link halaman 1,2,3,... for($i=1;$i<=$jmlHal;$i++){ if ($i != $halaman){ echo "<a href=$_SERVER[PHP_SELF]?halaman=$i>| $i | </a>"; } else { echo " $i "; } } //Link ke halaman berikutnya (Next) if ($halaman < $jmlHal){ $next = $halaman + 1; echo "<a href=$_SERVER[PHP_SELF]?halaman=$next> | Next >></a>"; }else{ echo "| Next >> </center>"; } ?> </td> </tr> </table> </body> </html>

Gb.php <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Guest Book</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <table width="500" border="0" align="center"> <tr> <td> <? include "tampilbuku.php"; ?> </td> </tr> <tr> <td> <hr size="1" color="#000000" noshade> <br> <? include "bukutamu.php"; ?> </td> </tr> </table> </body> </html> Koneksi.php <? $host="localhost"; $user="root"; $pass="password"; $db="sekolahan"; $con=mysql_connect($host,$user,$pass) or die ("Koneksi Gagal! ".mysql_error); mysql_select_db($db,$con) or die ("database tidak ada! ".mysql_error()); ?>

Anda mungkin juga menyukai