Prodi Sistem Informasi | Belajar HTML dan PHP | Skripsi SI
1000 Penghafal Quran
Pengobatan Ruqyah Mandiri
Sistem Informasi (S1)
Manajemen Informatika
Komputer dan Pendidikan
Blog | Kontak | Siap Kerja | Sertifikat | PrivacyPolicy | Inggris Arab | Daftar Isi

Saturday, December 28, 2013

Cara Membuat Forum Dengan PHP



1.      Software:
·         WampServer 2.2
·         Apache 2.2.21
·         PHP 5.3.10
·         MySQL 5.5.20


2.      Buat database: ikhbaar
3.      Buat tabel: forum
Column
Type
Length
Extra
ID_topik
Integer
5
Auto_Increment
nama
Varchar
50

email
Varchar
50

topik
Varchar
255

isi
Text


ID_replay
Integer
5

tanggal
Varchar
20


4.      Buat file: back.png; forum.gif; forum.png; kab.jpg; kanan.jpg; kib.jpg; kiri.jpg; reply.jpg (biar mudah lihat file download di akhir tutorial ini). Simpan di folder gambar
5.      Semua file gambar dan php simpan di folder …ikhbaar\forum
6.      Buat file: 4koneksi.php
Ketik script berikut:
<html>
<head>
</head>
<body>
<?php
ini_set('display_errors',FALSE);
$host="localhost";
$user="root";
$pass="";
$db="ikhbaar";
$entries=3;


$koneksi=mysql_connect($host,$user,$pass);
$tanggal=date("Y-m-d H:i:s");

if ($koneksi)
{
     //echo "berhasil : )";
}else{
     ?><script language="javascript">alert("Gagal Koneksi Database MySql !!")</script><?php
}

//Sumber: http://ri32.wordpress.com
?>

</body>
</html>


7.       Buat file: 4forum_utama.php
Ketik script berikut:
<html>
<head><title>Forum</title></head><br>
<table width="529" border="0" cellpadding="0" cellspacing="0" bordercolor="#99CC99" align="center">
  <tr>
    <td width="5%" align="right"><img src="./gambar/kiri.jpg"></td>
    <td width="81%" bgcolor="#5686c6" ><div align="center"><strong><font face="verdana" size="2" color="#FFFFFF">FORUM</font></strong></div></td>
    <td width="14%"><img src="./gambar/kanan.jpg"></td>
  </tr>
  <tr>
    <td><div align="center"></div></td>
    <td><table width="503" align="center">
      <tr>
        <td width="495"><?php
                 include "4koneksi.php";
                
                
                 ?>
              <p align="center"><font face="verdana" size="2">
                <?php
                 //untuk paging
                 $query=mysql_db_query($db,"select * from forum where ID_replay=0 order by tanggal desc",$koneksi); //input
                 $get_pages=mysql_num_rows($query);
                
                 if ($get_pages>$entries)  //proses
                 {
                             echo "Halaman : ";
                             $pages=1;
                             while($pages<=ceil($get_pages/$entries))
                             {
                                         if ($pages!=1)
                                         {
                                                     echo " | ";
                                         }
                             ?>
                <a href="4forum_utama.php?id=<?php echo ($pages-1); ?> " style="text-decoration:none"><font size="2" face="verdana" color="#009900"><?php echo $pages; ?></font></a>
                <?php
                                                     $pages++;
                             }
                 }else{
                             $pages=0;
                 }
                 ?>
              </font></p>
          <?php
                 //akhir paging
    
    
                 //proses halaman
                 $page=(int)$_GET['id'];
                 $offset=$page*$entries;
                 $result=mysql_db_query($db,"select * from forum where ID_replay=0 order by tanggal desc limit $offset,$entries",$koneksi); //output
                 $jumlah=mysql_num_rows($query);
                
                
                 if ($jumlah){
                             ?>
              <p align="center"><font color='#0066FF' face='verdana' size='2'><?php echo $_GET['status'] ?></font></p>
                               <p align="center"><font color="#FF0000" face='verdana' size='2'><blink><?php echo $_GET['error'] ?></blink></font></p>
          <table width="483" height="89"   border="0" align="center">
                <tr>
                  <td width="223" bgcolor="#e8e8e8"><div align="center"><b><font face="verdana" size="2">TOPIK</font></b></div></td>
                  <td width="59" bgcolor="#e8e8e8"><div align="center"><b><font face="verdana" size="2">Balasan</font></b></div></td>
                  <td width="187" bgcolor="#e8e8e8"><div align="center"><b><font face="verdana" size="2">Publikasi</font></b></div></td>
                </tr>
                <?php
                            
                             while ($row=mysql_fetch_array($result))
                             {
                                         $ID_topik=$row[0];
                                         $nama=$row[1];
                                         $email=$row[2];
                                         $topik=$row[3];
                                         $isi=$row[4];
                                         $ID_replay=$row[5];
                                         $tanggal=$row[6];     
                                        
                                         //jumlah replay setiap topik
                                         $replay=mysql_db_query($db,"select * from forum where ID_replay='$ID_topik'",$koneksi);
                                         $jml=mysql_num_rows($replay);
                             ?>
                <tr>
                  <td align="left"><b><a href="4forum_tampil.php?ID_topik=<?php echo $ID_topik;?>" style="text-decoration:none ">
                                           <img src="./gambar/forum.gif" border="0"><font face="verdana" size="2" color="#0033FF"><?php echo $topik;?></font></a> </b><br>
                      <font face="Courier New, Courier, mono" size="2"><?php echo $isi;?></font> </td>
                  <td align="center"><font face="verdana" size="2"><?php echo $jml; ?></font> </td>
                  <td align="left"><font face="verdana" size="-4" color="#666666"><?php echo $tanggal; ?></font>
                                           <font face="verdana" size="-4" color="#666666">Penulis: <?php echo $nama; ?> </font> </td>
                </tr>
                <tr>
                  <td colspan="3"><hr></td>
                </tr>
                <?php
                             }
                             ?>
            </table>
          <?php
                            
                 }else{
                             ?>
              <p align="center"><font color="#FF0000" face="verdana" size="2"><b>Belum ada data!!</b></font>
                  <?php
                 }
                 ?>
              </p>
          <p align="center"><a href="4forum_baru.php" style="text-decoration:none" title="Membuat Topik Baru"><img src="./gambar/forum.png" border="0"></a></p>
          </td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td align="right"><img src="./gambar/kib.jpg"></td>
    <td bgcolor="#5686c6" ><div align="center"><strong><font face="verdana" size="1" color="#333333">Jumlah Topik : <?php echo $jumlah; ?></font></strong></div></td>
    <td><img src="./gambar/kab.jpg"></td>
  </tr>
</table>
<p><a href="index.php?page=11" style="text-decoration:none" title="Membuat Topik Baru"></a></p>

<p align="center"><font color="#FF0000" face='verdana' size='2'><blink></blink></font></p>
</html>
<?
//Sumber: http://ri32.wordpress.com
?>


8.      Buat file: 4forum_tampil.php
Ketik script berikut:
<html>
<head><title>Forum</title></head><br>
<table width="45%" border="0" cellpadding="0" cellspacing="0" bordercolor="#99CC99" align="center">
<tr>
     <td width="2%" align="right"><img src="./gambar/kiri.jpg"></td>
     <td width="95%" bgcolor="#5686c6" ><div align="center"><strong><font face="verdana" size="2" color="#FFFFFF">Tampilan Forum</font></strong></div></td>
     <td width="3%"><img src="./gambar/kanan.jpg"></td>
</tr>
<tr>
     <td>&nbsp;</td>
     <td><table width="489" align="center">
                 <tr><td width="481">
                
                 <table width="133%" border="0">
                 <tr>
                             <td bgcolor="#CCCCFF" align="left">
                             <?php
                             #menampilkan topik
                             $ID_topik=$_GET['ID_topik'];
                            
                             include"4koneksi.php";
                             $query=mysql_db_query($db,"select * from forum where ID_topik='$ID_topik'",$koneksi); //untuk posting
                             $quey=mysql_db_query($db,"select * from forum where ID_replay='$ID_topik'",$koneksi); //untuk jumlah replay
                             $jml=mysql_num_rows($quey); //untuk jumlah replay
                            
                             while ($row=mysql_fetch_array($query))
                             {
                                         $ID_topik=$row[0];
                                         $nama=$row[1];
                                         $email=$row[2];
                                         $topik=$row[3];
                                         $isi=$row[4];
                                         $ID_replay=$row[5];
                                         $tanggal=$row[6];     
                             }
                                         //isi dari forum yang di tampilkan
                                         echo "<b>"."Topik : ".$topik."</b>"."<br>";
                                         ?><font face="verdana" size="1" color="#666666"><?php
                                        
                                         echo "Dikirim : ".$tanggal."<br>";
                                         ?>Oleh : <a href="mailto:<?php echo $email;?>" style="text-decoration:none" ><?php echo $nama; ?></a><br><?php
                                         echo "Hit : ".$jml." Balasan"."<br>";
                                        
                                         ?></font><br><font face="verdana" size="2"><?php
                                        
                                         echo $isi;
                                         echo "</font>";
                                        
                             ?>
                             </td>
                 </tr>
                 <tr>
                             <td align="left">
                             <?php
                            
                            
                             ?><p align="center"><font face="verdana" size="2"><?php
                             //untuk paging
                             $query2=mysql_db_query($db,"select * from forum where ID_replay='$ID_topik' order by tanggal desc",$koneksi); //input
                             $get_pages=mysql_num_rows($query2);
                            
                             if ($get_pages>$entries)  //proses
                             {
                                         echo "<br>Halaman : ";
                                         $pages=1;
                                         while($pages<=ceil($get_pages/$entries))
                                         {
                                                     if ($pages!=1)
                                                     {
                                                                 echo " | ";
                                                     }
                                         ?>
                                         <a href="index.php?page=9&id=<?php echo ($pages-1); ?>&ID_topik=<?php echo $_GET['ID_topik']; ?> " style="text-decoration:none"><font face="verdana" size="2" color="#009900"><?php echo $pages; ?></font></a>
                                          <?php
                                                                 $pages++;
                                         }
                             }else{
                                         $pages=0;
                             }
                             ?></font></p><?php
                             //akhir paging
                
                
                             //proses halaman
                             $page=(int)$_GET['id'];
                             $offset=$page*$entries;
                             $result=mysql_db_query($db,"select * from forum where ID_replay='$ID_topik' order by tanggal desc limit $offset,$entries",$koneksi); //output
                             $jumlah=mysql_num_rows($query2);
                            
                            
                             if($jumlah){
                            
                                         while ($row2=mysql_fetch_array($result))
                                         {
                                                     $ID_topik2=$row2[0];
                                                     $nama2=$row2[1];
                                                     $email2=$row2[2];
                                                     $topik2=$row2[3];
                                                     $isi2=$row2[4];
                                                     $ID_replay2=$row2[5];
                                                     $tanggal2=$row2[6]; 
                                                    
                                                    
                                                     ?><br><br><font face="verdana" size="2"><b>Bls : <?php echo $topik2 ?></b></font>
                                                     <font face="verdana" size="1" color="#666666"><?php
                                                     echo "Posted : ".$tanggal2;
                                                     ?> By : <a href="mailto:<?php echo $email2;?>" style="text-decoration:none "><?php echo $nama2; ?></a><?php
                                                     ?></font><?php
                                                    
                                                     echo "<br><br><font face='verdana' size='2'>";
                                                     echo $isi2;
                                                     echo "<hr></font>";
                                         }
                                        
                             }else{
                                         ?>
                                         <p align="center"><font color="#0066FF" face="verdana" size="2"><blink>Belum ada data!!</blink></font></p>
                                         <?php
                             }
                                        
                            
                             ?>
                             </td>
                 </tr>
                 <tr>
                             <td>
                                         <center>
                                           <p><a href="index.php?page=10&ID_topik=<?php echo $ID_topik; ?>&topik=<?php echo $topik;?>" style="text-decoration:none ">
                                               </a><a href="4forum_utama.php" title="Kembali"><img src="./gambar/back.png" alt="kembali" border="0"></a>
                                                       <a href="4forum_balas.php?ID_topik=<?php echo $ID_topik; ?>&topik=<?php echo $topik;?>" style="text-decoration:none "><img src="./gambar/reply.gif" border="0"></a></p>
                                          
                                   </center>
                             </td>
                 </tr>
                 </table>
                
                 </td></tr>
     </table>
     </td>
     <td width="3%"></td>
</tr>
<tr>
     <td align="right"><img src="./gambar/kib.jpg"></td>
     <td bgcolor="#5686c6" ><div align="center"><strong><font face="verdana" size="3"></font></strong></div></td>
     <td><img src="./gambar/kab.jpg"></td>
</tr>
</table>
<p>&nbsp;</p>
</html>

<?
//Sumber: http://ri32.wordpress.com
?>

9.      Buat file: 4forum_baru.php
Ketik script berikut:
<?php
include "4koneksi.php";

if(isset($_POST['nama']))
{
     $nama=$_POST['nama'];
     $email=$_POST['email'];
     $topik=$_POST['topik'];
     $isi=$_POST['isi'];
     $tanggal;
    
    
     if (empty($nama) || empty($email) || empty($topik) || empty($isi))
     {
                 echo "<script> document.location.href='4forum_baru.php?status=Maaf, Data Anda belum lengkap!!'; </script>";
     }else{
                
                 $query=mysql_db_query($db,"insert into forum(nama,email,topik,isi,tanggal) values('$nama','$email','$topik','$isi','$tanggal')",$koneksi);
                
                 if($query)
                 {
                             echo "<script> document.location.href='4forum_utama.php?status=Berhasil Membuat Topik Baru'; </script>";
                 }else{
                             echo "<script> alert('Gagal Query!!'); </script>";
                 }
     }

}else{
     unset($_POST['nama']);
}


?>
<html><head><title>Forum</title></head><br>
<center>
<table width="22%" border="0" cellpadding="0" cellspacing="0" bordercolor="#99CC99">
<tr>
     <td width="22%" align="right"><img src="./gambar/kiri.jpg"></td>
     <td width="60%" bgcolor="#5686c6" ><div align="center"><strong><font face="verdana" size="2" color="#FFFFFF">New Forum</font></strong></div></td>
     <td width="2%"><img src="./gambar/kanan.jpg"></td>
</tr>
<tr>
     <td>&nbsp;</td>
     <td>
     <table width="331" align="center">
                 <tr><td width="269">
                 <center>
                 <font color="#FF0000" face='verdana' size='2'><blink><?php echo $_GET['status'] ?></blink></font><br><br>
                 <form action="4forum_baru.php" method="post" name="form1">
                
                 <table width="100%" border="0" align="center">
                 <tr >
                             <td align="left"><font face="verdana" size="2">Nama</font></td><td>:</td><td align="left">
                             <input type="text" name="nama" size="20"></td>
                 </tr>
                
                 <tr>
                             <td align="left"><font face="verdana" size="2">Email</font></td><td>:</td><td align="left">
                             <input type="text" size="20" name="email"></td>
                 </tr>
                
                 <tr>
                             <td align="left"><font face="verdana" size="2">TOPIK</font></td><td>:</td><td align="left">
                             <input type="text" name="topik" size="20"></td>
                 </tr>
                
                 <tr>
                             <td align="left"><font face="verdana" size="2">Isi</font></td><td>:</td><td align="left"><textarea name="isi" cols="20" rows="10"></textarea></td>
                 </tr>
                
                 <tr>
                             <td><a href="4forum_utama.php" title="Kembali"><img src="./gambar/back.png" border="0"></a></td>
                             <td></td>
                             <td><input type="submit" name="submit" value="Kirim"></td>
                 </tr>
                 </table>
                 </center>
                 </form>
                
                 </td></tr>
     </table>
     </td>
     <td>&nbsp;</td>
     <td width="16%"></td>
</tr>
<tr>
     <td align="right"><img src="./gambar/kib.jpg"></td>
     <td bgcolor="#5686c6" ><div align="center"><strong><font face="verdana" size="3"></font></strong></div></td>
     <td><img src="./gambar/kab.jpg"></td>
</tr>
</table>
</center>
</html>

<?
//Sumber: http://ri32.wordpress.com
?>

10.  Buat file: 4forum_balas.php
Ketik script berikut:
<?php
include "4koneksi.php";
if(isset($_POST['nama']))
{
     $nama=$_POST['nama'];
     $email=$_POST['email'];
     $topik=$_POST['topik'];
     $isi=$_POST['isi'];
     $ID_topik=$_POST['ID_topik'];
    
     if (empty($nama) || empty($email) || empty($topik) || empty($isi))
     {
                 ?><script language="javascript">document.location.href='4forum_balas.php?ID_topik=<?php echo $ID_topik;?>&topik=<?php echo $topik;?>&status=Maaf, Data Anda masih kosong!!'; </script>";</script><?php
     }else{
                 $query=mysql_db_query($db,"insert into forum(nama,email,topik,isi,tanggal,ID_replay) values('$nama','$email','$topik','$isi','$tanggal','$ID_topik')",$koneksi);
    
                
                 if($query)
                 {
                             echo "<script>alert('Berhasil mengisi reply!!');</script>";
                             ?><script language="javascript">document.location.href='4forum_tampil.php?ID_topik=<?php echo $ID_topik;?>'; </script>";</script><?php
                 }else{
                             echo "<script>alert('gagal!!');</script>";
                 }
     }
}else{
     unset($_POST['nama']);
}


?>
<html>
<head><title>Forum</title></head><br>
<center><br>
<table width="25%" border="0" cellpadding="0" cellspacing="0" bordercolor="#99CC99">
<tr>
     <td width="2%" align="right"><img src="./img/kiri.jpg"></td>
     <td width="90%" bgcolor="#5686c6" ><div align="center"><strong><font face="verdana" size="2" color="#FFFFFF">Balas Forum</font></strong></div></td>
     <td width="6%"><img src="./img/kanan.jpg"></td>
</tr>
<tr>
     <td>&nbsp;</td>
     <td>
     <table width="331" align="center">
                 <tr><td width="269">
                 <center><font color="#FF0000" face='verdana' size='2'><blink><?php echo $_GET['status'] ?></blink></font><br><br></center>
                 <form action="4forum_balas.php" method="post" name="form1">
                 <table width="100%" border="0">
                 <tr >
                             <td align="left"><font face="verdana" size="2">ID</font></td><td>:</td><td align="left">
                             <input type="hidden" value="<?php echo $_GET['ID_topik']; ?>" name="ID_topik"><font face="verdana" size="2"><?php echo $_GET['ID_topik']; ?></font></td>
                 </tr>
                
                
                
                 <tr >
                             <td align="left"><font face="verdana" size="2">Nama</font></td><td>:</td><td align="left">
                             <input type="text" size="20" name="nama"></td>
                 </tr>
                
                 <tr>
                             <td align="left"><font face="verdana" size="2">Email</font></td><td>:</td><td align="left">
                             <input type="text" name="email" size="20"></td>
                 </tr>
                
                 <tr>
                             <td align="left"><font face="verdana" size="2">Topik</font></td><td>:</td><td align="left">
                             <input type="text" value="<?php echo $_GET['topik']; ?>" name="topik" size="33"></td>
                 </tr>
                
                
                
                 <tr>
                             <td align="left"><font face="verdana" size="2">Isi</font></td><td>:</td><td align="left"><textarea name="isi" cols="25" rows="10"></textarea></td>
                 </tr>
                
                 <tr>
                             <td>
                             <a href="4forum_tampil.php?ID_topik=<?php echo $_GET['ID_topik']; ?>&topik=<?php echo $_GET['topik'];?>" style="text-decoration:none" title="Kembali">
                             <img src="./gambar/back.png" border="0">
                             </a>
                             </td>
                             <td></td>
                             <td><input type="submit" name="submit" value="POST"></td>
                 </tr>
                 </table>
                 </form>
                
                
                 </td></tr>
     </table>
     </td>
     <td>&nbsp;</td>
     <td width="2%"></td>
</tr>
<tr>
     <td align="right"><img src="./img/kib.jpg"></td>
     <td bgcolor="#5686c6" ><div align="center"><strong><font face="verdana" size="3"></font></strong></div></td>
     <td><img src="./img/kab.jpg"></td>
</tr>
</table>
</center>
</html>

<?
//Sumber: http://ri32.wordpress.com
?>
11.  Hasilnya:





***
Sumber: http://ri32.wordpress.com

"Boleh Konsultasi Masuk Jurusan Sistem Informasi via IG atau Tiktok."
Tips Skripsi Program Studi Sistem Informasi

1 comment: