Oke sekarang saya akan memberikan sedikit tutorial sederhana bagaimana membuat forum Diskusi dengan menggunakan PHP dan MySql... Langsung aja yah...
Pertama buat database dengan nama "forum" tanpa tanda petik...
Lalu masukkan perintah SQL berikut...
[code]
CREATE TABLE forum_posting (
postid bigint(20) NOT NULL auto_increment,
author varchar(255) NOT NULL default '',
title varchar(255) NOT NULL default '',
post mediumtext NOT NULL,
showtime varchar(255) NOT NULL default '',
realtime bigint(20) NOT NULL default '0',
lastposter varchar(255) NOT NULL default '',
numreplies bigint(20) NOT NULL default '0',
parentid bigint(20) NOT NULL default '0',
lastrepliedto bigint(20) NOT NULL default '0',
PRIMARY KEY (postid)
)
[/code]
Lalu buat connect.php
[code]
$db = mysql_connect("localhost", "root", "cruzenaldo") or die("Gak Bisa Koneksi.");
if(!$db)
die("Gak Ada Databasenya");
if(!mysql_select_db("forum",$db))
die("Gak Ada Databasenya.");
if(!get_magic_quotes_gpc())
{
$_GET = array_map('mysql_real_escape_string', $_GET);
$_POST = array_map('mysql_real_escape_string', $_POST);
$_COOKIE = array_map('mysql_real_escape_string', $_COOKIE);
}
else
{
$_GET = array_map('stripslashes', $_GET);
$_POST = array_map('stripslashes', $_POST);
$_COOKIE = array_map('stripslashes', $_COOKIE);
$_GET = array_map('mysql_real_escape_string', $_GET);
$_POST = array_map('mysql_real_escape_string', $_POST);
$_COOKIE = array_map('mysql_real_escape_string', $_COOKIE);
}
?>
[/code]
Ini file CSS-nya... Untuk memperbagus aja
Simpan dengan nama "Style.css"
[code]
[/code]
Nah disini kita memerlukan 4 buah file yang akan kita gunakan untuk menampilkan semua threads (index.php), File untuk melakukan posting
(post.php), untuk menampilkan pesan (message.php) dan untuk melakukan reply (reply.php)
Pertama index.php
[code]
include "connect.php"; //untuk melakukan koneksi db
print "";
print "Topik Baru
";
print "
";
print " ";
$getthreads="SELECT * from forum_posting where parentid='0' order by lastrepliedto DESC";
$getthreads2=mysql_query($getthreads) or die("Tidak Dapat Memulai Thread");
while($getthreads3=mysql_fetch_array($getthreads2))
{
$getthreads3[title]=strip_tags($getthreads3[title]);
$getthreads3[author]=strip_tags($getthreads3[author]);
print " ";
}
print "
Topik | Nama | Balasan | Balasan Terakhir |
$getthreads3[title] | $getthreads3[author] | $getthreads3[numreplies] | $getthreads3[showtime] Pesan Terakhir Dari $getthreads3[lastposter] |
?>
[/code]
Lalu message.php
[code]
include "connect.php"; //koneksi db
$id=$_GET['id'];
print "";
print "Kembali Ke Forum-Topik Baru-Balas
";
print " ";
print " ";
$gettopic="SELECT * from forum_posting where postid='$id'";
$gettopic2=mysql_query($gettopic) or die("Tidak Dapat Memulai Topik");
$gettopic3=mysql_fetch_array($gettopic2);
print " ";
$getreplies="Select * from forum_posting where parentid='$id' order by postid desc";
$getreplies2=mysql_query($getreplies) or die("Could not get replies");
while($getreplies3=mysql_fetch_array($getreplies2))
{
print " ";
}
print "
Author | Post |
$gettopic3[author] | Last replied to at $gettopic3[showtime] "; $message=strip_tags($gettopic3['post']); $message=nl2br($message); print "$message "; print " |
$getreplies3[author] | Last replied to at $getreplies3[showtime] "; $message=strip_tags($getreplies3['post']); $message=nl2br($message); print "$message "; print " |
?>
[/code]
Lalu post.php
[code]
include "connect.php";
print "";
print " ";
print " ";
print "
Posting Sebuah Pesan |
"; if(isset($_POST['submit'])) { $name=$_POST['name']; $yourpost=$_POST['yourpost']; $subject=$_POST['subject']; if(strlen($name)<1) { print "Nama Masih Kosong."; } else if(strlen($yourpost)<1) { print "Postingan Masih Kosong."; } else if(strlen($subject)<1) { print "Subjek Masih Kosong."; } else { $thedate=date("U"); $displaytime=date("F j, Y, g:i a"); //Skrip untuk mencegah HTML injection $subject=strip_tags($subject); $name=strip_tags($name); $yourpost=strip_tags($yourpost); $insertpost="INSERT INTO forum_posting(author,title,post,showtime,realtime,lastposter) values('$name','$subject','$yourpost','$displaytime','$thedate','$name')"; mysql_query($insertpost) or die("Could not insert post"); //insert post print "Berhasil Melakukan Postinga, Kembali Ke Forum."; } } else { print " "; print "Nama: "; print " "; print "Subjek: "; print " "; print "Pesan: "; print " "; print ""; } print " |
?>
[/code]
reply.php
[code]
include "connect.php";
print "";
print " ";
print " ";
print "
Balas |
"; if(isset($_POST['submit'])) { $name=$_POST['name']; $yourpost=$_POST['yourpost']; $subject=$_POST['subject']; $id=$_POST['id']; if(strlen($name)<1) { print "Nama Masih Kosong."; } else if(strlen($yourpost)<1) { print "Pesan masih Kosong."; } else { $thedate=date("U"); $displaytime=date("F j, Y, g:i a"); $subject=strip_tags($subject); $name=strip_tags($name); $yourpost=strip_tags($yourpost); $insertpost="INSERT INTO forum_posting(author,title,post,showtime,realtime,lastposter,parentid) values('$name','$subject','$yourpost','$displaytime','$thedate','$name','$id')"; mysql_query($insertpost) or die("Tidak Dapat Memasukkan Postingan"); $updatepost="Update forum_posting set numreplies=numreplies+'1', lastposter='$name',showtime='$displaytime', lastrepliedto='$thedate' where postid='$id'"; mysql_query($updatepost) or die("Tidak Dapat Mengupdate Postingan"); print "Pesan Telah Berhasil, Kembali Ke Message."; } } else { $id=$_GET['id']; print " "; print ""; print "Nama: "; print " "; print "Pesan: "; print " "; print ""; } print " |
?>
[/code]
Letakkan semuanya di dalam satu folder dan jalankan... Semoga berguna dan selamat menikmati
Jadinya kayak gini...
* Contact
cruz3n@jasakom.org
cruzenaldo@gmail.com
* Blog Jelek Dan Sederhana
http://cruzenaldo.blogspot.com
* Thanks
~ JESUS CHRIST, My EVERYTHING... Without YOU im NOTHING
~ Bokap dan Keluarga dirumah
~ All Jasakomers yang telah membuat hidup saya masih penuh warna... ;p
~ Master2 Yang suka nongkrong di FORUM, mana Bro artikel Lo ditunggu disini
~ Witha Rasmana a.k.a Chrn0 (I Love You...)
~ Dan untuk Kalian yang dah baca artikel sederhana ini
~ Jasakom Gak Akan Mati...
0 komentar:
Posting Komentar