398,025 Members | 3,779 Online
Bytes IT Community

What You Need

By Blair Ireland
Senior Editor, TheScripts.com

Discussion Forums with PHP

People are made to talk, or just voice their opinions anyway. Get a lot of these people together, and you have developed a community. It is these communities that define what a web site is, and whether or not it will be successful. The question is now, how do I do it?

With PHP of course, using our trusty old MySQL database to back it. Don't be scared off though, this is not as complicated as you may think it to be. This tutorial will outline the steps to create such a discussion board, teaching you a number of things on the way. Yes, I know, Phorum (http://www.phorum.org/) is a free discussion board, also made with PHP and using SQL databases. The thing is, how can I teach you a few things by just forwarding you to a different site? Exactly.

We should start our tutorial with a checklist of things we need, so you don't get stuck half-way through the tutorial not knowing what is going on, or why something isn't working.

  1. A Web Server (obviously)
  2. PHP installed on this server (duh!)
  3. MySQL on this server as well
  4. Time - Don't expect to learn this stuff without putting time into it.
  5. A Brain (we have to store this information somewhere, and your hard drive is only so convenient)
  6. Caffeine - Mr. Coffee Bean loves us programmers, as we stay up late nights and put his children through college.
I must tell you that I hate the look of threaded discussion boards. I love the look of the Ultimate Bulletin Board though, so we will use that design. So now we need to make our tables......

CREATE TABLE posts (
   ID int(5) DEFAULT '0' NOT NULL auto_increment,
   TopicID int(5) DEFAULT '0' NOT NULL,
   Name varchar(50) NOT NULL,
   Email varchar(50) NOT NULL,
   Password varchar(50) NOT NULL,
   TimeStamp varchar(10) NOT NULL,
   Post text NOT NULL,
   PRIMARY KEY (ID)
);

CREATE TABLE topics (
   ID int(5) DEFAULT '0' NOT NULL auto_increment,
   TopicName varchar(50) NOT NULL,
   PRIMARY KEY (ID)
);

Why two? We will be making an index page, listing all of the available topics to comment on. The other part, messages, will hold all the info on actual posts by the users. The fields will kind of explain themselves as I go, so lets move on.

  Viewing Posts »