Membuat Message Board dengan PHP dan MySql

Jika anda menggunakan mysql client standard (console) berikut langkah-langkahnya :

root: mysql �h localhost �u root �p password

Berikut penjelasannya :

    => Localhost, adalah alamat host dari MySQL server
    => Password, adalah password untuk akses ke MySQL 
    => Server Root, adalah user untuk akses ke MySQL server

Dan jika anda berhasil mengakses ke MySQL server maka akan muncul pesan seperti :

Welcome to the MySQL monitor. Commands end with ; or Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 35901 to server version: 4.0.12-standard-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql>

Setelah anda berhasil mengakses kedalam MySQL server buatlah satu database, caranya

mysql> CREATE DATABASE namadatabase

Atau jika sudah memiliki database dan anda ingin menggunakan database tersebut untuk menyimpan datanya :

mysql > use namadatabase

    Selanjutnya buatlah satu table untuk menyimpan data messages board

CREATE TABLE sms (

id bigint(5) unsigned NOT NULL auto_increment, sms_from varchar(60) default NULL,

sms_msg varchar(255) default NULL, sms_date varchar(30) default NULL, sms_email varchar(60) default NULL,

host enum('minahasa','knet') default NULL, PRIMARY KEY (id)

) TYPE=MyISAM;

Setelah database disiapkan sekarang kita akan beralih ke PHP scriptnya. Disini kita akan membuat 4 file php :

  1. config.php (untuk mengatur semua config terutama untuk koneksi ke database server  MySQL).
  2. tampilan.php (tampilan utama dari messages board).
  3. smile.php (untuk menampilkan emoticons/smiles).
  4. sms.php (untuk menampilkan hasil/data messages board)

$conn=mysql_connect("$sqlhost","$sqluser","$sqlpasswd") or die("<p align=center>CAN NOT CONNECT TO MYSQL SERVER");

mysql_query("use $sqldb");

extract($_SERVER,"EXTR_PREFIX_SAME"); extract($HTTP_ENV_VARS,"EXTR_PREFIX_SAME"); extract($HTTP_GET_VARS,"EXTR_PREFIX_SAME"); extract($HTTP_POST_VARS,"EXTR_PREFIX_SAME");

?>

File : Tampilan.php

<html>

<head>

<title>Messages boar by ipen</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

<body>

<table width="165" border="0" align="center" cellpadding="0"

cellspacing="0">

<tr>

<td><table width="100%" border="0" style="background:#FAE852;border-bottom:1px solid

#FCF29A;border-top:1px solid #FCF29A" align="center" cellpadding="1" cellspacing="1">

<tr>

<td><strong> Messages Board</strong></td>

</tr>

</table></td>

</tr>

<tr>

<td> <script language="JavaScript">

function clrTh() {

document.sms.smsnama.value="";

}

function clrThs() {

document.sms.smspesan.value="";

}

function opnsmile() { window.open('smile.php','smile',"scrollbars=yes,toolbar=no,resizable=n o,screenX=1,screenY=1,menubar=no,location=no,width=300,height=400,stat us=no");

}

</script>

<table width="100%" border="0" style="border-right:1px solid

#FCF29A;border-left:1px solid #FCF29A;border-bottom:1px solid #FCF29A" align="center" cellpadding="3" cellspacing="1">

<tr>

<td><iframe frameborder="0" height="150" width="98%" marginheight="0" name="ifr" scrolling="auto" marginwidth="0" src="sms.php"></iframe>

</td>

</tr>

<tr>

<td height="255"> <form action="sms.php" method="post" name="sms" target="ifr">

Nama<br>

<input name="smsnama" type="text" id="smsnama" style="border:1px solid

#CCCCCC;background:#FFFFFF;color:#000000;width:150;font-size:10;font-f amily:verdana" onFocus="clrTh();">

<br>

Pesan<br>

<textarea name="smspesan" rows="5" id="smspesan" style="border:1px solid

#CCCCCC;background:#FFFFFF;color:#000000;width:150;font-size:10;font-f amily:verdana"></textarea>

<br>

(<a href="javascript:opnsmile();">smilies</a>)

<p></p>

<p>

<input name="sendsms" type="submit" id="sendsms" style="background:#FFD800;color:#000000" value="SEND">

<input name="sendsms2" type="reset" id="sendsms2" style="background:#FFD800;color:#000000" value="CLEAR">

</p>

</form></td>

</tr>

</table>

</td>

</tr>

</table>

</body>

</html>



File : smile.php



<html><head><title>messages board Smilies - ipen</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<style> BODY{

scrollbar-highlight-color:#000000; scrollbar-shadow-color:#000000; scrollbar-track-color:#250512; scrollbar-face-color:#250512; scrollbar-arrow-color:#FFFFFF; scrollbar-darkshadow-color:#868584; scrollbar-3dlight-color:#555555;

}

</style>

<STYLE>.nounder{text-decoration:none;font-family:verdana;

font-size:12}</STYLE>

<SCRIPT lang="Javascript" type="text/javascript">

function add_smilie(a_smilie){

if(window.opener.document.sms!=window.undef){

window.opener.document.sms.smspesan.value+=" "+a_smilie+"

";

//window.opener.document.sms.smspesan.focus();

}

}



function wc(ty, sp, w, pic){

document.write('<tr align="center"><td bgcolor="#DDDDDD"><a href="javascript:add_smilie(\''+ty+'\')" class="nounder"><B>'+ty+'</B></a></td><TD bgcolor="#FFFFFF"></TD><td bgcolor="#DDDDDD">'+sp+'<a

href="javascript:add_smilie(\''+ty+'\')"><img src="smilies/'+pic+'.gif"

width="'+w+'" border=0></a></td></tr>');

}

</SCRIPT></HEAD>

<body bgcolor="#FFD800" text="#000000" link="#000000" vlink="#000000">

<table width="0%" border="0" RULES=NONE cellspacing="1" cellpadding="2" align="center"><tr bgcolor="#a4acb8" valign="center" align="center"><td nowrap><b>Smilie Code</b></td><TD bgcolor="#FFFFFF"></TD><td nowrap><b>Image<BR>Replacement</b></td></tr><SCRIPT> wc(":fight:","",33,"fight");

wc(":kiss:","",34,"kiss");

wc(":com:","",40,"playcom");

wc(":)","",15,"smile");

wc(":(","",15,"sad");

wc(":o","",15,"shocked");

wc(":D","",15,"biggrin");

wc(";)","",15,"wink");

wc(":p","",15,"tongue");

wc(":artist:","",15,"artist");

wc(":bowling:","",15,"bowl");

wc(":mad:","",15,"mad");

wc(":dizzy:","",15,"dizzy");

wc(":nono:","",15,"nono"); wc(":eyepatch:","",15,"pirate"); wc(":sick:","",15,"sick"); wc(":cry:","",15,"cry"); wc(":uhh:","",15,"uhh"); wc(":wacko:","",15,"wacko");

wc(":yinyang:","",15,"yin-yang");

wc(":frog:","&nbsp;&nbsp;",25,"frog");

</SCRIPT></TABLE></BODY></HTML>





File : sms.php



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<title>messages board by ipen</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<style> BODY{

scrollbar-highlight-color:#FFD800; scrollbar-shadow-color:#FFD800; scrollbar-track-color:#FFE401; scrollbar-face-color:#FFE401; scrollbar-arrow-color:#000000; scrollbar-darkshadow-color:#868584; scrollbar-3dlight-color:#FFD800;

}

</style>

</head>



<body bgcolor="#FFE401" text="#000000" link="#000000" vlink="#000000" alink="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<?php

include("config.php"); function smiles($msgsmiles) { global $smsmsg;

$msgsmiles=str_replace(":)","<img src=\"smilies/smile.gif\">",$msgsmiles);

$msgsmiles=str_replace(":com:","<img src=\"smilies/playcom.gif\">",$msgsmiles);

$msgsmiles=str_replace(":kiss:","<img src=\"smilies/kiss.gif\">",$msgsmiles);

$msgsmiles=str_replace(":fight:","<img src=\"smilies/fight.gif\">",$msgsmiles);

$msgsmiles=str_replace(":(","<img src=\"smilies/sad.gif\">",$msgsmiles);

$msgsmiles=str_replace(":o","<img src=\"smilies/shocked.gif\">",$msgsmiles);

$msgsmiles=str_replace(":D","<img src=\"smilies/biggrin.gif\">",$msgsmiles);

$msgsmiles=str_replace(";)","<img src=\"smilies/wink.gif\">",$msgsmiles);

$msgsmiles=str_replace(":p","<img src=\"smilies/tongue.gif\">",$msgsmiles);

$msgsmiles=str_replace(":artist:","<img src=\"smilies/artist.gif\">",$msgsmiles);

$msgsmiles=str_replace(":bowling:","<img src=\"smilies/bowl.gif\">",$msgsmiles);

$msgsmiles=str_replace(":mad:","<img src=\"smilies/mad.gif\">",$msgsmiles);

$msgsmiles=str_replace(":dizzy:","<img src=\"smilies/dizzy.gif\">",$msgsmiles);

$msgsmiles=str_replace(":nono:","<img src=\"smilies/nono.gif\">",$msgsmiles);

$msgsmiles=str_replace(":eyepatch:","<img src=\"smilies/pirate.gif\">",$msgsmiles);

$msgsmiles=str_replace(":sick:","<img src=\"smilies/sick.gif\">",$msgsmiles);

$msgsmiles=str_replace(":cry:","<img src=\"smilies/cry.gif\">",$msgsmiles);

$msgsmiles=str_replace(":uhh:","<img src=\"smilies/uhh.gif\">",$msgsmiles);

$msgsmiles=str_replace(":wacko:","<img src=\"smilies/wacko.gif\">",$msgsmiles);

$msgsmiles=str_replace(":yinyang:","<img src=\"smilies/yin-yang.gif\">",$msgsmiles);

$msgsmiles=str_replace(":frog:","<img src=\"smilies/frog.gif\">",$msgsmiles);

$smsmsg=$msgsmiles;

}

if ($sendsms) {

$smsdate=date("d Y F H:i");

if (($smspesan) and ($smsnama)) {



$smsnama=strip_tags($smsnama);

$smspesan=strip_tags($smspesan);

$getSMS=mysql_query("select * from ". $prefix ."sms where host='minahasa' and sms_msg='$smspesan'");

$SMSold=mysql_fetch_array($getSMS); if (!$SMSold[sms_msg]) { mysql_query("insert into ". $prefix ."sms

(sms_from,sms_date,sms_msg,host) values

('$smsnama','$smsdate','$smspesan','minahasa')

");

}

}

}

$getSMS=mysql_query("select * from ". $prefix ."sms where host='minahasa' order by id desc limit 0,50");

while ($sms=mysql_fetch_array($getSMS)) {

unset($smsfrom); unset($smsmsg); unset($smspesanexp);

$smsnamaexp=explode(" ",$sms[sms_from]);

$smspesanexp=explode(" ",$sms[sms_msg]);

for ($in=0;$in<=count($smsnamaexp);$in++) {

if (strlen($smsnamaexp[$in]) > 15) {

$smsnamaexp[$in]=substr($smsnamaexp[$in],0,15). "

" .substr($smsnamaexp[$in],16,strlen($smsnamaexp[$in]));

}

$smsfrom .=" " .$smsnamaexp[$in];

}

for ($ip=0;$ip<=count($smspesanexp);$ip++) {

if (strlen($smspesanexp[$ip]) > 15) {



$smspesanexp[$ip]=substr($smspesanexp[$ip],0,15). "

" .substr($smspesanexp[$ip],16,strlen($smspesanexp[$ip]));

}

$smsmsg.=" " .$smspesanexp[$ip];

}

$smsmsg=str_replace("..","., ",$smsmsg);

smiles($smsmsg);

echo "

<table border=0 cellpadding=0 width=100% cellspacing=0 align=center><tr><td>

<b><font color=#996633>$smsfrom</font></b><br>

$smsmsg

</td></tr>

</table><br> ";

}

?>

</body>

</html>




Comments

Popular posts from this blog

Cara Membuat Halaman Login Hotspot Berbeda pada 1 Mikrotik

UltraISO Premium Edition v9.5.3

Arti OSAKMJ