Sering sekali disebuah blog ditambahkan dengan shoutbox yang dibuat dengan cara mengkopi link yang kita peroleh setelah kita peroleh dari server yang menyediakan aplikasi shoutbox misalnya di sini baik yang free ataupun yang premium. Tapi perlu diingat ada beberapa kelemahan jika menggunakan cara di atas. Setiap orang mau mbuka blog kita harus mengeload server shoutbox tersebut. Itu berarti waktu akses ke blog kita menjadi jauh lebih lama.
Begini nih cara membuat shoutbox dengan php:
1. Buat database (klo di blog tidak perlu mbuat database lagi)
CREATE DATABASE `contoh_web` ;
USE contoh_web;
2. Buat tabel shoutbox
CREATE TABLE shoutbox;
3. Buat field-field pada table shoutbox
CREATE TABLE `shoutbox` (
`id` INT NOT NULL AUTO_INCREMENT ,
`tanggal` DATETIME NOT NULL ,
`nama` VARCHAR( 20 ) NOT NULL ,
`email` VARCHAR( 50 ) NOT NULL ,
`pesan` VARCHAR( 200 ) NOT NULL ,
PRIMARY KEY ( `id` )
) TYPE = MYISAM ;
4.Buat server.php
5. Buat shoutbox.php
<html>
<head>
<tittle>Contoh shoutbox</title>
</head>
<body>
<form id=”form1″ name=”form1″ method=”post” action=”insert.php”>
<table width=”600″ border=”0″ cellspacing=”2″ cellpadding=”0″>
<tr>
<td width=”197″>Nama</td>
<td width=”19″>:</td>
<td width=”376″><input type=”text” name=”nama” /></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input type=”text” name=”email” /></td>
</tr>
<tr>
<td>Comment</td>
<td>:</td>
<td><textarea name=”komentar”></textarea></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type=”submit” name=”Submit” value=”Ok” />
<input name=”Reset” type=”reset” id=”Reset” value=”Cancel” /></td>
</tr>
</table>
</form>
</body>
</html>
6. Buat insert.php
<?php
include (“server.php”);
$koneksi=mysql_connect($host,$user,$pass) or die (mysql_error());
mysql_select_db($db,$koneksi) or die (mysql_error());
$query=mysql_query(“insert into shoutbox values (”,sysdate(),’$nama’,'$email’,'$komentar’)”,$koneksi) or die (mysql_error());
$redirect=rtrim ($_SERVER['HTTP_REFERER'],”?”);
header (“Location:$redirect”);
?>
7. Untuk menampilkan isi shoutbox Tambahkan kode ini di shoutbox.php
<?
include (“server.php”);
$koneksi=mysql_connect($host,$user,$pass) or die (mysql_error());
mysql_select_db($db,$koneksi) or die (mysql_error());
$query=mysql_query(“select * from shoutbox order by tanggal desc limit 0,10″,$koneksi) or die (mysql_error());
$jumlah=mysql_num_rows($query);
while ($row=mysql_fetch_array($query))
{
echo “
“;
echo $row[1];
echo “
“;
//echo $row[2];
//echo “
“;
echo $row[3];
echo “
“;
echo $row[4];
echo “
“;
}
?>

