Anda di halaman 1dari 68

Membuat Web Forum Dengan Php dan Mysql

Juli 30, 2011 by triconstantine

ayo belajar php dengan susah payah saya ahirnya bisa menyelesaikan tutorial php ini kalow mau copy paste postingan saya harap cantumkan jg nama saya,,,,,terimaksih atas perhatiannya.. dalam artikel Membuat Web Forum Dengan Php dan Mysql ini saya akan memberikan beberapa contoh script php yg sya buat maaf bila di dalam artikel Membuat Web Forum Dengan Php dan Mysql kalau masih kurang memuaskan ya namanya juga sama sama belajar semoga artikel Membuat Web Forum Dengan Php dan Mysql ini bermanfaat untuk anda.. saya persembahkan artikel Membuat Web Forum Dengan Php dan Mysql untuk para pembaca yang tercinta. kenalan yuk.. kenalin aquw anak baru dari bogor, umur 15 tahun, cowok(just berondong),,,,numb hape catet ia kalow di perluin,,,,,,085718383409. tanpa basa basi pertama siapkan dulu header.jpg webnya..lalu download j query dan fancy box..kalow blom tahuw j query dan fancy box itu apa silahkan tanya ke paman google ok

truz siapin jg satu folder bernama upload..jgn lupa siapin jg bg.jpg untu latar belakang,,,,, nah yang inni simpan dengan nama connection.php Code:

<?php //create connetion to MYSQL database$conn=mysql_connect(local


host,root,lilia33)or die(Can not connect to database!); mysql_select_db(a3202487_imagen);?> ini index.php Code:

<!DOCTYPE html PUBLIC "//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or g/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="ContentType" content="text/html; charset=iso-8859-1" /> <title>Imagenatoria</title> <style type="text/css"> body{font-family:"Comic Sans Ms ";} a:link {text-decoration:none; color:#FF0000;} a:visited {text-decoration:none; color:#FF0000;} a:hover {text-decoration:underline; color:#FF0000;} a:active {text-decoration:underline; color:#FF0000;} </style> </head> <body background="bg.jpg"> <table align="center"><tr><td><img border="1" width=800" src="header.jpg"/></td></tr></table> <table align="center" width="800"><tr><td><tr>
<td bgcolor="><table width=" border=0 cellpadding=0 bordercolor=#FFFF FF> <tr> <td width=99 align=right> <td width=885 align=right><strong>Diskusikanlah topik yang bermanfaat di f orum kami <?php

//connect to database include connection.php; ?> </tr> <tr> <td></td> <td></td> </tr> <tr valign=top> <td><table bgcolor=" width=151 valign=top align=center> <tr align=left> <tr width=143 valign=top><td>Menu<td></tr> </tr> <tr align=left> <tr valign=top><td><strong><a href=new_topic.php?title=&amp;desc=&amp; action=&amp;msg=>New Post</a></strong></td></tr> </tr> <tr align=left> <td><a valign=top href=profile.php?action=><strong>My Profile</strong></a > </td> </tr> <tr valign=top align=left> <td><a href=gallery.php><strong>Gallery</strong></a> </td> </tr> <tr align=left> <td><a href=login.php><strong>Login</strong></a></td> </tr> <tr valign=top align=left> <td><a href=search.php><strong>Search</strong></a></td> </tr> <tr valign=top align=left> <td><a href=main_forum.php><strong>Langsung Ke Forum</strong></a></td> </tr> <tr valign=top align=left> <td><strong><a href=register.php>Register</a></strong></td> </tr> </table> <strong><a href=new_topic.php?title=&desc=&action=&msg=></a></strong> </td>

<td><?php //connect to database include connection.php; //select data from table topic $query=SELECT * FROM topic order by post_date desc limit 0, 5; $result=mysql_query($query); while($row=mysql_fetch_array($result)){ //display topic echo <font color=green size=+1>.$row['title'].</font><br>; //get who post the topic $query1=SELECT CONCAT_WS( ,first_name,last_name) as name_1 from user _login where email=.$row['post_by_user'].; $result1=mysql_query($query1)or die(mysql_error()); $row1=mysql_fetch_array($result1); echo Post By :.$row1['name_1'].<br>; //display post_date echo Post Date : .$row['post_date'].<br><br>; //display description echo $row['description']; //get number comment to topic $query2=select count(topic_id) as num_comment from comment where topic_id= .$row['topic_id']; $result2=mysql_query($query2); $row2=mysql_fetch_array($result2); echo <p align=right><a href=new_comment.php?topic=.$row['topic_id'].&m sg=0&action=>New Comment</a> | <a href=comment.php?topic=.$row['topic_ id'].>Comment (.$row2['num_comment'].)</a></p><hr>; } ?> </td> </tr> </table></td></tr></table> <div align=center>&copy;Tio Web Production<br/>SMKF Galenium Bogor</di v> </body> </html> suka-gallery.php

Code:

<?php include 'session.php'; ?><? $id=$_GET['id']; include('connection.php'); $result = mysql_query("SELECT * FROM foto WHERE id='$id' "); $row=mysql_fetch_array($result); ?> Anda sudah menyukai ini <?$suka_awal=$row['suka'];
$suka_ahir=$row['suka']+1; mysql_query(UPDATE foto SET suka = $suka_ahir WHERE id = $id); $expire=time()+60*60*24*30; setcookie($id, $id, $expire); ?> comment.php Code:

<!DOCTYPE html PUBLIC "//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or g/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="ContentType" content="text/html; charset=iso-8859-1" /> <title>Display Comment</title><style type="text/css"> body{font-family:"";} a:link {text-decoration:none; color:#FF0000;} a:visited {text-decoration:none; color:#FF0000;} a:hover {text-decoration:underline; color:#FF0000;} a:active {text-decoration:underline; color:#FF0000;} </style></head><body bgcolor=" background=bg.jpg>

<div style=width:800; margin:0 auto;> <table width=800 border=0 align=center> <tr> <th scope=col><img src=header.jpg width=800 /></th> </tr> </table><table width=800 align=center border=0 cellpadding=0 cellspacin g=0> <tr> <td></td> </tr> <tr> <td bgcolor="><a href=main_forum.php>Main Forum</a> &gt; Comment </td> </tr> <tr> <td bgcolor="><strong>List Comment for Topic : <?php //display topic title // connect to database include connection.php; $query=select title from topic where topic_id=.$_REQUEST['topic']; $result=mysql_query($query); $row=mysql_fetch_array($result); echo $row['title']; ?></strong></td> </tr> <tr> <td bgcolor="><?php //displaying list comment $query2=select * from comment where topic_id=.$_REQUEST['topic']; $result2=mysql_query($query2); $row2=mysql_fetch_array($result2); if($row2){ do{ echo Post date : .$row2['post_date']; //get user name that post the comment $query3=select * from user_login where email=.$row2['post_by_user'].; $result3=mysql_query($query3); $row3=mysql_fetch_array($result3);

echo <br>Post by : .$row3['first_name']. .$row3['last_name']; echo <p>.$row2['description'].</p><hr>; }while($row2=mysql_fetch_array($result2)); } ?> </td> </tr> <tr> <td></td> </tr> </table> </div> <div align=center>&copy;Tio Web Production<br/>SMKF Galenium Bogor</di v></body> </body> </html> dellete-gallery.php Code:

<?php include 'session.php'; ?> <?php //file delete-gallery.php //koneksi ke database include('connection.php'); if(isset($_GET['id'])){ $id = (int) $_GET['id']; $sql = "select * from foto where id='$id'"; $result = mysql_query($sql); if(mysql_num_rows($result) > 0 ){ $data = mysql_fetch_array($result); //delete file @unlink('upload/'.$data['nama_file']); //delete data di database mysql_query("delete from foto where id='$id'"); }

} header("Location: gallery.php"); ?>


do_login.php Code:

<?php include 'session.php'; ?> <?php //file delete-gallery.php //koneksi ke database include('connection.php'); if(isset($_GET['id'])){ $id = (int) $_GET['id']; $sql = "select * from foto where id='$id'"; $result = mysql_query($sql); if(mysql_num_rows($result) > 0 ){ $data = mysql_fetch_array($result); //delete file @unlink('upload/'.$data['nama_file']); //delete data di database mysql_query("delete from foto where id='$id'"); } } header("Location: gallery.php"); ?>
edit-gallery.php Code:

<?php include 'session.php'; ?><?php //file edit-gallery.php

//koneksi ke database include('connection.php'); if($_POST){ //jika tombol update ditekan dan data terkir im ke server //bentuk sql query untuk update $update = "update foto set deskripsi='".$_POST['deskrips i']."' "; if($_FILES['file']['size'] > 0 && $_FILES['file']['error '] == 0){ //update gambar hanya jika user memilih file b aru $move = move_uploaded_file($_FILES['file']['tmp_name'], "upload/".$_FILES['file']['name']); if($move){ $update .= ", nama_file='".$_FILES['file']['name']."'"; } } $update .= " where id='".$_POST['id']."'"; mysql_query($update); //update data ke database header("Location: gallery.php"); exit; } ?> <html> <head> <title>Edit Picture</title> </head> <body> <form name="form1" action="" method="post" enctype="mult ipart/form-data"> <?php $sql = "select * from foto where id='".intval($_GET['id' ])."'"; $data = mysql_fetch_array(mysql_query($sql)); ?> <!-- menampilkan gambar sebelumnya -->

<img src="upload/<?php echo $data['nama_file'];?>" alt=" " width="200"/><br/> File: <input type="file" name="file" id="file"/><br/> <!-- menampilkan deskripsi --> Deskripsi: <textarea name="deskripsi" id="deskripsi"><?p hp echo $data['deskripsi'];?></textarea><br/> <input type="submit" name="save" value="Update"/> <input type="hidden" name="id" value="<?php echo $data[' id'];?>"/> </form> </body> </html>
form.php Code:

<html> <head> <title>New Picture</title> </head> <body> <table><tr> <form name="form1" action="savegallery.php" method="post" enctype="multipart/formdata"> <td> File:</td><td> <input type="file" name="file" id="f ile"/><br/> </td></tr><tr> <td>Deskripsi:</td><td> <textarea name="deskripsi" rows= "20" cols="100" id="deskripsi"></textarea><br/> </td> <input type="submit" name="save" value="Upload"/> </form></tr> </table> </body> </html>
login.php

Code:

<!DOCTYPE html PUBLIC "//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or g/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="ContentType" content="text/html; charset=iso-8859-1" /> <title>Login to Forum</title> <style type="text/css"> <!-body { background-color: ; } --> </style></head><body background=bg.jpg>
<div style=width:700px; margin:0 auto;> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <table width=100% border=0 cellspacing=0 cellpadding=0> <tr> <td></td> </tr> <tr> <td align=center bgcolor=#FECF9C> <form id=form1 name=form1 method=post action=do_login.php> <table width=60% border=0 cellspacing=0 cellpadding=0> <tr> <td>Email Address </td> <td><input name=email type=text id=email /></td> </tr> <tr> <td>Password</td> <td><input name=password type=password id=password /></td> </tr> <tr> <td>&nbsp;</td>

<td><input type=submit name=Submit value=Login /></td> </tr> <tr> <td>&nbsp;</td> <td>&nbsp;</td> </tr> </table> </form> </td> </tr> <tr> <td></td> </tr> </table> </div> </body> </html> logout.php Code:

<?php session_start(); $_SESSION=array(); session_destroy(); setcookie('PHPSESSID','',time()-3600,'/','',0); header("location: index.php"); ?>


main_forum.php Code:

<?php include 'session.php'; ?> <!DOCTYPE html PUBLIC "-

//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or g/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="ContentType" content="text/html; charset=iso-8859-1" /> <title>Forum Kami</title> <style type="text/css"> <!-body { background-color:; } --> </style><style type="text/css"> body{font-family:"";} a:link {text-decoration:none; color:#FF0000;} a:visited {text-decoration:none; color:#FF0000;} a:hover {text-decoration:underline; color:#FF0000;} a:active {text-decoration:underline; color:#FF0000;} </style> </head><body background=bg.jpg><table width=85% border=0 cellspaci
ng=0 cellpadding=0 align=center> <tr><td><img src=header.jpg width=800 /></td></td> <tr> <td> </td> </tr> <tr> <td><table width=800 border=0 cellpadding=0> <tr> <td width=18% align=right> </td> <td width=82% align=right><strong>Selamat datang di forum kami, <?php //connect to database include connection.php; //get the user name $query=select * from user_login where email=.$_SESSION['user_forum'].; $result=mysql_query($query);

$row=mysql_fetch_array($result); echo .$row['first_name']; echo <a href=logout.php title=Logout>Logout</a>; ?></strong></td> </tr> <tr> <td></td> <td></td> </tr> <tr valign=top> <td><table bgcolor="width=122 align=center> <tr align=left> <th width=143 scope=col>Menu</th> </tr> <tr align=left> <th scope=col><strong><a href=new_topic.php?title=&amp;desc=&amp;action =&amp;msg=>New Post</a></strong></th> </tr> <tr align=left> <td><a href=profile.php?action=><strong>My Profile</strong></a> </td> </tr> <tr align=left> <td><a href=gallery.php><strong>Gallery</strong></a> </td> </tr> <tr align=left> <td><a href=search.php><strong>Search</strong></a></td> </tr> </table></td> <td><?php //connect to database include connection.php;//select data from table topic $query=SELECT * FROM topic order by topic_id desc; //untuk page $sqlCount = select count(topic_id) from topic; $rsCount = mysql_fetch_array(mysql_query($sqlCount)); $banyakData = $rsCount[0]; $page = isset($_GET['page']) ? $_GET['page'] : 1; $limit = 15;

$mulai_dari = $limit * ($page - 1); $sql_limit = select * FROM topic order by topic_id desc limit $mulai_dari, $limit ;$result=mysql_query($sql_limit); while($row=mysql_fetch_array($result)){ //display topic echo <font color=green size=+1>.$row['title'].</font><br>; //get who post the topic $query1=SELECT CONCAT_WS( ,first_name,last_name) as name_1 from user _login where email=.$row['post_by_user'].; $result1=mysql_query($query1)or die(mysql_error()); $row1=mysql_fetch_array($result1); echo Post By :.$row1['name_1'].<br>; //display post_date echo Post Date : .$row['post_date'].<br><br>; //display description echo $row['description']; //get number comment to topic $query2=select count(topic_id) as num_comment from comment where topic_id= .$row['topic_id']; $result2=mysql_query($query2); $row2=mysql_fetch_array($result2); echo <p align=right><a href=new_comment.php?topic=.$row['topic_id'].&m sg=0&action=>New Comment</a> | <a href=comment.php?topic=.$row['topic_ id'].>Comment (.$row2['num_comment'].)</a></p><hr>; } ?> </td> </tr> <tr> <td> </td> <td> </td> </tr> </table></td> </tr> <tr> <td> <? //membuat pagination

$banyakHalaman = ceil($banyakData / $limit); echo Halaman: ; for($i = 1; $i <= $banyakHalaman; $i++){ if($page != $i){ echo [<a href="main_forum.php?page='.$i.'">'.$i.'</a>] ; }else{ echo [<a href="main_forum.php?page='.$i.'">'.$i.'</a>] ; } } ?> </td> </tr> </table> <div align=center>&copy;Tio Web Production<br/>SMKF Galenium Bogor</di v></body> </html>

new_comment.php Code:

<?php include 'session.php';//creating script to save data when user press subm
it button if($_REQUEST['action']==insert){ $comment=$_POST['comment']; $topic_id=$_POST['topic_id']; if($comment!= && $topic_id!=){ //connect to database include connection.php; //creating query $query=INSERT INTO comment (topic_id, description, post_date, post_by_user) values ($topic_id, $comment, NOW(), .$_SESSION['user_forum'].); $result=@mysql_query($query); if($result){ header(location: main_forum.php);

}else{ header(location: new_comment.php?topic=$topic_id&msg=2); } }else{ header(location: new_comment.php?topic=$topic_id&msg=1); } } ?> <!DOCTYPE html PUBLIC //W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD /xhtml1-transitional.dtd&gt; <html xmlns=http://www.w3.org/1999/xhtml&gt; <head> <meta http-equiv=Content-Type content=text/html; charset=iso-8859-1 /> <title>Post New Comment</title> <style type=text/css> <! body { background-color:; } > </style><style type=text/css> body{font-family:";} a:link {text-decoration:none; color:#FF0000;} a:visited {text-decoration:none; color:#FF0000;} a:hover {text-decoration:underline; color:#FF0000;} a:active {text-decoration:underline; color:#FF0000;} </style> </head><body background=bg.jpg> <div style=width:800; margin:0 auto;> <table width=800 border=0 align=center> <tr> <th width=278 scope=col><img width=800 src=header.jpg /></th> </tr> </table> <table align=center width=800 border=0 cellspacing=0 cellpadding=0> <tr> <td></td>

</tr> <tr> <td bgcolor="><h2>Post New Comment </h2></td> </tr> <tr> <td bgcolor="><form id=form1 name=form1 method=post action="> <table width=100% border=0 cellspacing=0 cellpadding=0> <tr> <td colspan=2 align=center valign=top><?php //displaying error message if($_REQUEST['msg']==1){ echo <font size=+1 color=red>Error!! Data incomplete</font>;}elseif($_RE QUEST['msg']==2){ echo <font size=+1 color=red>Error!! Can not save data to database.</font>; }else{ echo ; } ?> </td> </tr> <tr> <td width=18% valign=top><strong>Topic</strong></td> <td width=82%><input name=topic_id type=hidden id=topic_id value=< ?php echo $_REQUEST['topic'];?> /><?php //get topic title //connect to database include connection.php; //select title from table topic $query=select title from topic where topic_id=.$_REQUEST['topic'].; //executing query $result=mysql_query($query); //retrieving result to array $row=mysql_fetch_array($result); //display topic title echo $row['title']; ?></td> </tr> <tr> <td valign=top><strong>Comment</strong></td>

<td><textarea name=comment cols=40 rows=6 id=comment></textarea> </td> </tr> <tr> <td> </td> <td><input type=submit name=Submit value=Submit /> <input name=action type=hidden id=action value=insert /></td> </tr> <tr> <td> </td> <td> </td> </tr> </table> </form> </td> </tr> <tr> <td> </td> </tr> <tr> <td></td> </tr> </table> </div> <div align=center>&copy;Tio Web Production<br/>SMKF Galenium Bogor</di v></body> </body> </html> new_topic.php Code:

<?php include 'session.php';//connect to database


include connection.php; //create variable $title=$_REQUEST['title'];

$desc=$_REQUEST['desc']; // check are user click button save if($_REQUEST['action']==insert){//check if title and description no empty if($title== || $desc==){ header(Location: new_topic.php?msg=1); }else{ //data no empty //save data to database $query=INSERT INTO topic (title,description,post_date,post_by_user) value ($title,'$desc,NOW(),.$_SESSION['user_forum'].); $result=@mysql_query($query); if($result){ header(Location: main_forum.php); }else{ header(Location: new_topic.php?msg=2); } } }?> <!DOCTYPE html PUBLIC //W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD /xhtml1-transitional.dtd&gt; <html xmlns=http://www.w3.org/1999/xhtml&gt; <head> <meta http-equiv=Content-Type content=text/html; charset=iso-8859-1 /> <title>Post New Topic</title> </head> <style type=text/css> body{font-family:";} a:link {text-decoration:none; color:#FF0000;} a:visited {text-decoration:none; color:#FF0000;} a:hover {text-decoration:underline; color:#FF0000;} a:active {text-decoration:underline; color:#FF0000;} </style><body bgcolor=" background=bg.jpg> <div style=width:800px; margin:0 auto;> <table width=800 border=0 align=center> <tr> <th width=278 scope=col><img width=800 src=header.jpg /></th> </tr>

</table> <p> </p> <table width=800 border=0 cellspacing=0 cellpadding=0> <tr> <td></td> </tr> <tr> <td bgcolor=#FFCB7D><a href=main_forum.php>Main Forum</a> &gt; New Topic </td> </tr> <tr> <td align=center bgcolor="><?php if($_REQUEST['msg']==1){ echo <font color=red size=+1>Error!! Data incomplete</font>; }elseif($_REQUEST['msg']==2){ echo <font color=red size=+1>Can not save data to database!</font>; } ?> </td> </tr> <tr> <td bgcolor="><form id=form1 name=form1 method=post action="> <table width=100% border=0 cellpadding=0> <tr> <td width=30%>Title</td> <td><input name=title type=text id=title size=40 /></td> </tr> <tr> <td>Description</td> <td><textarea name=desc cols=40 rows=6 id=desc></textarea></td> </tr> <tr> <td> </td> <td><input type=submit name=Submit value=Save /> <input name=action type=hidden id=action value=insert /></td> </tr> <tr> <td> </td> <td> </td>

</tr> </table> </form> </td> </tr> <tr> <td bgcolor="> </td> </tr> <tr> <td</td> </tr> </table> </div> <div align=center>&copy;Tio Web Production<br/>SMKF Galenium Bogor</di v></body> </body> </html>

profile.php Code:

<?php include 'session.php';if($_REQUEST['action']==edit){


include connection.php; if($_POST['tfname']!= && $_POST['tpass1']!= && $_POST['tpass2']!= && $_ POST['tpass1']==$_POST['tpass2']){ $sql=update user_login set email=.$_POST['temail']., first_name=.$_POST[ 'tfname']., last_name=.$_POST['tlname']., password=.$_POST['tpass1']. where email=.$_POST['temail'].; $result=mysql_query($sql)or die(mysql_error()); } } ?> <!DOCTYPE html PUBLIC //W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD /xhtml1-transitional.dtd&gt;

<html xmlns=http://www.w3.org/1999/xhtml&gt; <head> <meta http-equiv=Content-Type content=text/html; charset=iso-8859-1 /> <title>User Profile</title> <style type=text/css> <! body { background-color: ; } > </style><style type=text/css> body{font-family:Comic Sans Ms ;} a:link {text-decoration:none; color:#FF0000;} a:visited {text-decoration:none; color:#FF0000;} a:hover {text-decoration:underline; color:#FF0000;} a:active {text-decoration:underline; color:#FF0000;} </style> </head><body background=bg.jpg> <table width=200 border=0 align=center> <tr> <th scope=col><img src=header.jpg/ width=800></th> </tr> </table> <br/> <table width=800 border=0 cellspacing=0 cellpadding=0 align=center> <tr> <td width=99%></td> </tr> <tr> <td bgcolor="><a href=main_forum.php>Main Forum</a> &gt; User Profile <?php include connection.php; $sql=select * from user_login where email=.$_SESSION['user_forum'].; $result=mysql_query($sql); $row=mysql_fetch_array($result); ?></td> </tr> <tr> <td bgcolor="><form id=form1 name=form1 method=post action=">

<table width=97% border=0 cellpadding=0 align=center bgcolor="> <tr > <td width=149 align=right>Email</td> <td width=9> </td> <td width=503><input name=temail type=text id=temail readonly=true value=<?php echo $row['email'];?> /></td> </tr> <tr> <td align=right>First Name </td> <td> </td> <td><input name=tfname type=text id=tfname value=<?php echo $row['fir st_name'];?> /></td> </tr> <tr> <td align=right>Last Name </td> <td> </td> <td><input name=tlname type=text id=tlname value=<?php echo $row['las t_name'];?> /></td> </tr> <tr> <td align=right>Password</td> <td> </td> <td><input name=tpass1 type=password id=tpass1 value=<?php echo $row ['password'];?> /></td> </tr> <tr> <td align=right>Retype Password </td> <td> </td> <td><input name=tpass2 type=password id=tpass2 value=<?php echo $row ['password'];?> /> <input name=action type=hidden id=action value=edit /></td> </tr> <tr> <td> </td> <td> </td> <td><input type=submit name=Submit value=Save /></td> </tr> </table>

</form> </td> </tr> <tr> <td<td width=1%></td> </tr> </table> <div align=center>&copy;Tio Web Production<br/>SMKF Galenium Bogor</di v></body> </body> </html> register.php Code:

<!DOCTYPE html PUBLIC "//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or g/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="ContentType" content="text/html; charset=iso-8859-1" /> <title>Registration</title> <style type="text/css"> body{font-family:"";} a:link {text-decoration:none; color:#FF0000;} a:visited {text-decoration:none; color:#FF0000;} a:hover {text-decoration:underline; color:#FF0000;} a:active {text-decoration:underline; color:#FF0000;} </style> <style type="text/css"> <!-body { background-color: ; } -->

</style></head><body background=bg.jpg>
<div style=width:700px; margin:0 auto;> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <table width=100% border=0 cellspacing=0 cellpadding=0> <tr> <td</td> </tr> <tr> <td bgcolor="><form id=form1 name=form1 method=post action=save_r egister.php> <table width=100% border=0 cellpadding=0> <tr> <td width=30%>Email</td> <td><input name=email type=text id=email /></td> </tr> <tr> <td>First Name </td> <td><input name=first_name type=text id=first_name /></td> </tr> <tr> <td>Last Name </td> <td><input name=last_name type=text id=last_name /></td> </tr> <tr> <td>Password</td> <td><input name=password1 type=password id=password1 /></td> </tr> <tr> <td>Retype Password </td> <td><input name=password2 type=password id=password2 /></td> </tr> <tr> <td>&nbsp;</td> <td><input type=submit name=Submit value=Register /></td> </tr> <tr> <td>&nbsp;</td> <td>&nbsp;</td>

</tr> </table> </form> </td> </tr> <tr> <td> </tr> </table> </div> </body> </html> save-gallery.php Code:

<?php include 'session.php'; ?><?php include 'session.php'; ?> <?php //koneksi ke database include('connection.php'); //upload file if(!empty($_FILES) && $_FILES['file']['size'] > 0 && $_F ILES['file']['error'] == 0){ $fileName = $_FILES['file']['name']; $move = move_uploaded_file($_FILES['file']['tmp_name'], 'upload/'.$fileName); if($move){ //simpan deskripsi dan nama file ke database $sql = "insert into foto (nama_file, deskripsi) values ('$fileName', '".$_POST['deskripsi']."')"; mysql_query($sql); header("Location: gallery.php"); exit;

} } ?>
save_register.php Code:

<!DOCTYPE html PUBLIC "//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or g/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="ContentType" content="text/html; charset=iso-8859-1" /> <title>Registration</title> <style type="text/css"> <!-body { background-color: black; } --> </style></head><body>
<div style=width:700px; margin:0 auto;> <table width=100% border=0 cellspacing=0 cellpadding=0> <tr> <td></td> </tr> <tr> <td align=center bgcolor=#FECD72> <?php // connect to database include connection.php;//create variable to store data $email=$_POST['email']; $first_name=$_POST['first_name']; $last_name=$_POST['last_name']; $password1=$_POST['password1']; $password2=$_POST['password2'];// CEK IF DATA NOT EMPTY

if($email== || $first_name== || $password1== || $password2==){ echo <h2>Sorry data incomplete</h2>;}else{ //cek if password anda retype password in same if($password1!=$password2){ echo <h2>Password and Retype Password must be in same!</h2>; }else{ //save data to database // creating query $query=INSERT INTO user_login (email, first_name, last_name, password) VA LUES ($email, $first_name, $last_name, $password1); $result=@mysql_query($query)or die(mysql_error()); if($result){ echo <h2>Registration Success</h2><br><a href=login.php>Continue Login</ a>; }else{ echo <h2>Error!! Can not save data to database!</h2>; } } } ?></td> </tr> <tr> <td></td> </tr> </table> </div> </body> </html>

search.php Code:

<!DOCTYPE html PUBLIC "//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or g/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="ContentType" content="text/html; charset=iso-8859-1" /> <title>search</title> </head> <body background="bg.jpg"> <!-- form quick search --> <form name="form1" method="get" action=""> Search : <input type="text" name="q" id="q"/> <input typ e="submit" value="Search"/> </form> <!-- menampilkan hasil pencarian --> <?php if(isset($_GET['q']) && $_GET['q']){ include('connection.php'); $q = $_GET['q']; $sql = "select * from topic where post_date like '%$q%' or title like '%$q%' or description like '%$q%' or post_by_ user like '%$q%'"; $result = mysql_query($sql); if(mysql_num_rows($result) > 0){ ?> <table> <tr> <td>tanggal</td> <td>judul</td> <td></td> <td>di buat oleh</td> </tr> <?php

while($topic = <tr> <td><?php echo <td><?php echo <td><?php echo <td><?php echo </tr> <?php }?> </table> <?php }else{ echo 'Data not } } ?> </body> </html>
session.php Code:

mysql_fetch_array($result)){?> $topic['post_date'];?></td> $topic['title'];?></td> $topic['description'];?></td> $topic['post_by_user'];?></td>

found!';

<?php session_start();//cek if user was login or not


if(!isset($_SESSION['agent_forum']) || ($_SESSION['agent_forum']!=md5($_SER VER['HTTP_USER_AGENT'])) ){ header(location: login.php); exit();} ?> oh iya saya hampir lupa, databasenya kayak gini.. Code:

-- phpMyAdmin SQL Dump -- version 2.11.4

-- http://www.phpmyadmin.net --- Host: localhost -- Generation Time: Jul 23, 2011 at 09:49 AM -- Server version: 5.1.57 -PHP Version: 5.2.17SET SQL_MODE=NO_AUTO_VALUE_ON_ZER
O; Database: `a3202487_imagen` - Table structure for table `comment` CREATE TABLE `comment` ( `topic_id` int(10) unsigned DEFAULT 0, `description` text, `post_date` datetime NOT NULL DEFAULT 0000-00-00 00:00:00, `post_by_user` varchar(50) NOT NULL DEFAULT ) ENGINE=MyISAM DEFAULT CHARSET=latin1; Dumping data for table `comment` Table structure for table `foto` CREATE TABLE `foto` ( `id` int(11) NOT NULL AUTO_INCREMENT, `nama_file` varchar(255) NOT NULL, `deskripsi` varchar(255) DEFAULT NULL, `suka` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

Dumping data for table `foto` Table structure for table `topic` CREATE TABLE `topic` ( `topic_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `title` varchar(255) NOT NULL DEFAULT , `description` text, `post_date` datetime NOT NULL DEFAULT 0000-00-00 00:00:00, `post_by_user` varchar(50) NOT NULL DEFAULT , PRIMARY KEY (`topic_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

ini contoh jadinya imagenatoria.tk ayo jangan nyerah teruslah belajar php maaf ia kalow acakan..aku pendatang baru,,,,, my facebook http://www.facebook.com/tri.constantine Membuat Web Forum Dengan Php dan Mysql

MEMBUAT FORUM DENGAN PHP


SENIN, DESEMBER 19, 2011 SHOECHARDEX PHELOE 5 COMMENTS

Sekedar share tidak mau repot mambaca.... saya kasi link donloadnya di bawah...dengan catatan mengganti semua script <? dengan <?php

pertama kita mambuat coneksinya dengan nama conn.php <html> <head> </head> <body> <?php ini_set('display_errors',FALSE); $host="localhost";

$user="root"; $pass=""; $db="kunokuno"; $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 }

?>

</body> </html>

kedua mambuat halaman utama untuk forum dengan nama forum.php <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="./img/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="./img/kanan.jpg"></td> </tr> <tr> <td><div align="center"></div></td> <td><table width="503" align="center"> <tr> <td width="495"> <?php include "conn.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="forum.php?id=<?php echo ($pages-1); ?> " style="textdecoration: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">Replay</font></b></div></td> <td width="187" bgcolor="#e8e8e8"><div align="center"><b><font face="verdana" size="2">Posting</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="forum-view.php?ID_topik=<?php echo $ID_topik;?>" style="text-decoration:none "> <img src="./img/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">Autor: <?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="forum-new.php" style="text-decoration:none" title="Membuat Topik Baru"><img src="./img/forum.png" border="0"></a></p> </td> </tr> </table></td>

</tr> <tr> <td align="right"><img src="./img/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="./img/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>

ketiga kita buat halaman untuk inputan datanya kita namai forum-new.php <?php include "conn.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='forum-new.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='forum.php?status=Berhasil Membuat Topik Baru'; </script>"; }else{ echo "<script> alert('Gagal Query!!'); </script>";

} }

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

?> <html><head><title>Forum Ri32</title></head><br> <center> <table width="22%" border="0" cellpadding="0" cellspacing="0" bordercolor="#99CC99"> <tr> <td width="22%" align="right"><img src="./img/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="./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> <form action="forum-new.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="forum.php" title="Kembali"><img src="./img/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="./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>

ke empat kita buat halaman selanjutnya kita namai forum-reply.php <?php include "conn.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='forumreply.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='forumview.php?ID_topik=<?php echo $ID_topik;?>'; </script>";</script><?php }else{ echo "<script>alert('gagal!!');</script>"; }

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

?> <html> <head><title>Forum Ri32</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">Reply 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="forum-reply.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="forum-view.php?ID_topik=<?php echo $_GET['ID_topik']; ?>&topik=<?php echo $_GET['topik'];?>" style="text-decoration:none" title="Kembali"> <img src="./img/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>

terakhir kita membuat halaman yang kita namai forum-view.php <html> <head><title>Forum Ri32</title></head><br> <table width="45%" border="0" cellpadding="0" cellspacing="0" bordercolor="#99CC99" align="center"> <tr> <td width="2%" align="right"><img src="./img/kiri.jpg"></td> <td width="95%" bgcolor="#5686c6" ><div align="center"><strong><font face="verdana" size="2" color="#FFFFFF">View Forum</font></strong></div></td> <td width="3%"><img src="./img/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"conn.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 "Posted : ".$tanggal."<br>"; ?>By : <a href="mailto:<?php echo $email;?>" style="text-decoration:none "><?php echo $nama; ?></a><br><?php echo "Hit : ".$jml." replay"."<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>Re : <?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="forum.php" title="Kembali"><img src="./img/back.png" alt="kembali" border="0"></a><a href="forum-reply.php?ID_topik=<?php echo $ID_topik; ?>&topik=<?php echo $topik;?>" style="text-decoration:none "><img src="./img/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="./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> <p>&nbsp;</p> </html>

Download script lengkap dan database nya di

Sini

overall dah jalan gan. namun masih ada eror 1 bagian yaitu paging di halaman view topik, ktika buat topik, trus masuk ke topiknya, ada 5orang komen, trus ad paging 1 dan 2, ketika di klik paging 1 atau 2 object not found, itu kenapa ya? mohon bantuannya

Nofel_Apen says:
5 November 2012 20.33 Reply

owh setelah saya liat2 agan salah ketik hehe, tadi di kodingan forum-view: <a href="index.php? seharusnya <a href="forum-view.php" nice bgt gan bermanfaat ^^

Membuat Forum Sederhana (PHP+Mysql)


Okle hari ini saya buat tutorial sederhana bagaimana membuat forum Diskusi dengan menggunakan PHP dan MySql... Langsung ke TKP... Pertama Siapkan secangkir kopi jangan lupa pake Ruti.. (optional.. ha..ha) lantas.. duduk manis ... buat database dengan nama "forum" tanpa tanda petik... (=namanya sich bebas ) Lalu masukkan perintah SQL berikut...

Code:
CREATE TABLE forum_posting (

postid bigint(20) NOT NULL auto_increment, author varchar(255) NOT NULL default '', default '',

title varchar(255) NOT NULL post mediumtext NOT NULL, showtime

varchar(255) NOT NULL default '', default '0',

realtime bigint(20) NOT NULL

lastposter varchar(255) NOT NULL default '', numreplies bigint(20) NOT NULL default '0', default '0',

parentid bigint(20) NOT NULL

lastrepliedto bigint(20) NOT NULL default '0', PRIMARY ) KEY (postid)

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); }

?>

Ini file CSS-nya... Untuk memperbagus aja Simpan dengan nama "Style.css" 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 print ""; print "; print " "Topik Baru "connect.php"; //untuk melakukan koneksi db

Topik $getthreads3[title]

Nama $getthreads3[author]

Balasan $getthreads3[numreplies]

Balasan Terakhir $getthreads3[showtime] Pesan Terakhir Dari $getthreads3[lastposter]

"; ?>

Lalu message.php Code:


include "connect.php"; //koneksi db $id=$_GET['id'];

print ""; print "; print " "Kembali Ke Forum-Topik Baru-Balas

Author $gettopic3[author]

Post 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 "

"; ?>

Lalu post.php Code:


include "connect.php"; 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 "

"; ?>

reply.php Code:
include print ""; print " "connect.php";

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 "

"; ?>

Letakkan semuanya di dalam satu folder dan jalankan... ...disini gunung dsana gunung.. jangan bingung.. hikz

Anda mungkin juga menyukai