How To: Make A Simple Php Forum System

free web hosting
Free Web Hosting > Computers & Tech > Programming > Scripting > PHP

How To: Make A Simple Php Forum System

Miles
Hello,
One of my first ever projects I embarked on when I began to understand PHP well was a forum system. I've decided to begin writing a tutorial to help people start one of their own. The code for this project is based on that of OakumBoard/cBoard, my own forum software which can be seen running at www.sonicxtremegm.co.cc

Anyways, time to start off, you must run this SQL query on an SQL database with a name of your choice:
CODE
s

CREATE TABLE `forums` (
  `id` int(3) NOT NULL auto_increment,
  `name` varchar(80) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3;

INSERT INTO `forums` (`id`, `name`) VALUES
(1, 'Test Forum'),


CREATE TABLE `members` (
  `id` int(4) NOT NULL auto_increment,
  `username` varchar(65) NOT NULL default '',
  `password` varchar(65) NOT NULL default '',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3;


CREATE TABLE `replies` (
  `topicid` int(4) NOT NULL,
  `reply_id` int(4) NOT NULL,
  `reply_user` varchar(50) NOT NULL,
  `reply_text` longtext NOT NULL,
  `reply_datetime` varchar(25) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;



CREATE TABLE `topics` (
  `id` tinyint(4) NOT NULL auto_increment,
  `title` varchar(180) NOT NULL,
  `text` longtext NOT NULL,
  `datetime` varchar(30) NOT NULL default '0',
  `user` varchar(80) NOT NULL,
  `reply` int(4) NOT NULL,
  `forumid` int(3) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=6;


Now, you create a file called conf.php. Inside it should be the text:
CODE
<?php

$host=    "[b]localhost[/b]"; // Host name
$username="[b]admin[/b]"; // Mysql username
$password="[b]adminone[/b]"; // Mysql password
$db_name= "[b]admindb[/b]"; // Database name


mysql_connect("$host", "$username", "$password")or die("Failed to connect to DB server");
mysql_select_db("$db_name")or die("Failed to select DB");
?>


Replace the bolded areas with the appriate value for your data.

 

 

 


Reply

yordan
Sorry for the contradiction, Miles. I would not say that this is a tutorial : this post shows the very nice program you made, it does not teach php.
However, I find your php-by-example approach very constructive. That's why I moved your topic here, where is most probably it's place.
Regards
Yordan

Reply

Feelay
I don't think you are done with this script or :S?
Because the only thing you have here is the MySQL table, and the database-connection file..

Reply

Miles
Haven't finished writing it out yet. By the way, there is more below.
You are now going to create the main files: index.php. This contains nearly all the coding for the forum. You will place the following within it:
CODE
<?php
$name =  $_COOKIE['username_cb'];
if ( $name == "" ) {
$name="Guest";
}
//---------------------------------------------------------
// Include all necessary files and find the requested page
//---------------------------------------------------------
include "conf.php";
//---------------------------------------------------------
// Prepare a few things
//---------------------------------------------------------
$page = $_GET['p'];
  if ($page=="")
{
$page = main;
}
switch ($page) {
//---------------------------------------------------------
// Show the list of forums
//---------------------------------------------------------
case "showforums":

echo "<table width=\"90%\" border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"1\" bgcolor=\"#CCCCCC\">
<tr>
<td width=\"6%\" align=\"center\" bgcolor=\"#E6E6E6\"><strong>#</strong></td>
<td width=\"76%\" align=\"center\" bgcolor=\"#E6E6E6\"><strong>Forum</strong></td>
<td width=\"18%\" align=\"center\" bgcolor=\"#E6E6E6\"><strong>Last Topic</strong></td>
</tr> ";

$sql="SELECT * FROM forums ORDER BY id ASC";
// Now to get the forums list done
$result=mysql_query($sql);
while($rows=mysql_fetch_array($result)){
echo "
<tr>
<td bgcolor=\"#FFFFFF\">".$rows['id']."</td>
<td align=\"left\" valign = \"top\" bgcolor=\"#FFFFFF\"><B><a href=\"index.php?p=showtopics&id=". $rows['id'] ."\">". $rows['name'] ."</a></b><BR>". $rows['desc'] ."</td>
<td bgcolor=\"#FFFFFF\">".$rows['lastpost']."</td>";
}
//Join it all up
echo "</table>";
break;
}
?>

More parts of this tutorial coming soon!

 

 

 


Reply

sparkx
Forums are often very large and require many pages. Most forum softwares take a long time to make. The one I made however only was a few PHP pages and already out ranks every other one I have seen but the method that you are using will take a lot more space then mine did. I would recommend that you finish your entire tutorial on one post and rather then posting code just make a .txt file, upload it and link to it. This would really help people follow your post's easier. Your post could be a good tutorial if you were to put all the code together but at the moment all I see is a good tutorial in the making that isn't quite ready to be posted yet.

Good luck,
Sparkx

Reply


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Recent Queries:-
  1. how to make a simple php forum - 16.08 hr back. (1)
  2. "simple php forum" - 37.96 hr back. (1)
  3. simple forum system - 151.95 hr back. (1)
Similar Topics

Keywords : , make, simple, php, forum, system

  1. Free Forum Hosting Type Script Help!
    Free forum hosting type script help!!! (2)
  2. Php Forum Cookies
    I need help on a php forum cookie. All suggestions welcome. (3)
    OK, I am making a forum in php (with a mysql database). It is much harder then I thought it would be
    but I have been getting along very well. I was just putting some finnishing things on it when I
    found a problem I couldn't figure out. All suggestions are welcome. Problem: I want my forum
    (like all forums) to remember what topics you have already read. I want to do this via cookies and
    at first I was think of having to topic ID to be saved in a string. Example (Cookie:
    %x%) x=the forum topic ID. Then to retrieve that data I would simply look for %x% inside the coo....
  3. Random Name Generator
    For a fantasy RPG forum (2)
    Well, I did this particular piece of coding a few days back, and I forgot to display it to you all
    here at AstaHost. I have just started a fantasy RPG forum. The naming rules are pretty strict
    because it has to be based on a construted langage called Pasen. No matter how much I explained, I
    thought, it would be hard for a newbie to understand the syllable formation constraints. Hence, I
    wrote a script and put it at my Drupal powered site, that generates random names for the four races
    for both genders. http://www.WiseTome.com/name-generator-for-chaos-and-order I ....
  4. Wordpress With Forum ?
    (2)
    Is there any software or MOD that could integrate WordPress with a forum ? I mean the posts /
    comments / User DB. I know of a site that makes a script called XDForums , but it supports WP 1.5
    not 2.0 .. and i have the latest version of WP installed. Plus the site is taking loads of time to
    release a new version of the forum software. Does anyone know a MOD that could integrate PhpBB
    forums to wordpress with the user DB etc .. ?? or could someone be kind enough to code it ? Thankx
    Regards Dhanesh. ....
  5. Forum Signature-image With Php
    Use PHP to create an image in real-time (8)
    With interest I have read these Topics. What I want to do with PHP is the following:
    Signatue-image This is the Forum Signature of my cousin, who lives in Europe. The image is
    generated in real-time. (Refresh the page, and see for yourself) My cousin refuses to tell me how
    he did this. But I want to do the same thing, also with PHP. Any ideas? Greetings, John. This
    is NOT a tutorial and in future you should be more careful about where you're posting your
    threads. Moved to Programming > Scripting. ....
  6. Script to allow only members to download media
    from a forum/board.. How to do it ? (18)
    I didnt know where to post this so i posted it here I wanna to know where to find a script where
    people have to register at your forum to download media off your website and i also wanna know what
    it is called. ------------------------------------------------------------- Next time you make a
    post - please be more specific about the topic. It helps a lot if your topic describes your post
    content in brief rather than having a "Help me" - which could mean anything. More often this
    wouldn't pique the interest of the readers at all and your post will get very few respo....
  7. How To Do The Security Confirmation
    see it when i register forum (3)
    How to do the security confirmation. When i register this forum, i see this. The image contain
    numbers and user must be fill in the number in image.....

    1. Looking for , make, simple, php, forum, system

Searching Video's for , make, simple, php, forum, system
advertisement




How To: Make A Simple Php Forum System



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE