[Tutorial] Making a Forum Software

aka ibebak

Paragon
Joined
Aug 7, 2008
Messages
1,181
Reaction score
0
FP$
6
Since so many out there want to, here is a simple tutorial.

I made this tutorial ages ago, over a year ago, it's very very very basic, I do not recommend that you actually use this code if you plan on building a software commercially, as some of it is very sloppy, outdated, and inefficient, but you could still learn a few things. This will only create a basic index page containing forums, and categories, I may post a more advanced tutorial later on.

Start off by creating your database file in order to connect to the mysql server
Code:
<?php
$mysql_host = "mysql";
$mysql_database = "DATABASE NAME HERE";
$mysql_user = "DATABASE USERNAME HERE";
$mysql_password = "PASSWORD HERE";

$connection = mysql_connect($mysql_host, $mysql_user, $mysql_password) or die("Could not connect to MySQL");
mysql_select_db($mysql_database, $connection) or die ("Database cannot be found.");
?>
What the above code does is connect you to your database. If your settings are wrong it will display "Could not connect to MySQL", if they are right but there is no database in your account, you will see, "Database cannot be found." and it will kill the connection.

Next create your MySQL database tables.
My settings are below.
Code:
CREATE TABLE `cat` (
  `cname` varchar(500) NOT NULL,
  `cid` tinyint(99) NOT NULL AUTO_INCREMENT,
  `cdesc` varchar(1000) NOT NULL,
  PRIMARY KEY (`cid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1;

CREATE TABLE `forum` (
  `fname` varchar(200) NOT NULL,
  `fid` tinyint(99) NOT NULL AUTO_INCREMENT,
  `pid` tinyint(99) NOT NULL,
  `fdesc` varchar(9999) NOT NULL,
  PRIMARY KEY (`fid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1;

CREATE TABLE `settings` (
  `title` varchar(20) NOT NULL,
  `online` tinyint(200) NOT NULL DEFAULT '1',
  `offlinemsg` varchar(9999) NOT NULL DEFAULT 'We are sorry. The administrator of this forum has turned the board offline for mantinance, please check again later.',
  KEY `title` (`title`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
That is simply a database query. You may be able to use these settings to create an install file if needed. I will make an install file tutorial later on.

Next you will start your coding. I will not go very far in depth or even show you my entire code. Just the PHP/SQL parts. The html, you can do on your own.

Code:
<?php
include ('dbconnect.php');
echo '<table>';
$cat = "SELECT * FROM cat ORDER BY cid asc";
$result = mysql_query($cat) or die(mysql_error());
while($catvar = mysql_fetch_array($result)){
echo '<tr><th colspan="1">'.$catvar['cname'].'<small> ( '.$catvar['cdesc'].' ) </small></th></tr>';
$forum = "SELECT * FROM forum WHERE forum.pid = ".$catvar['cid']." ORDER BY fid asc";
$result2 = mysql_query($forum) or die(mysql_error());
while($forumvar = mysql_fetch_array($result2)){
echo '<tr><td ><a href="./forum.php?='.$forumvar['fid'].'">'.$forumvar['fname'].'</a><br />'.$forumvar['fdesc'].'</td></tr>';
}
}
echo '</table>';
?>
Explanation: What this code is doing is connecting to the database and retrieving the information we specified and placing it into an html table.
Code:
$cat = "SELECT * FROM cat ORDER BY cid asc";
This connects to your dbconnect file and then retrieves everything (*) from the cat table and order's them by the categories id (cid) in ascending order.

Code:
$forum = "SELECT * FROM forum WHERE forum.pid = ".$catvar['cid']." ORDER BY fid asc";
This does a very similar thing. The main difference is, it checks the forum.pid (parent id) field and displays any that have the same pid as any of the categories (cid) therefor simply connection the child (forum) with it's parent (category).


That was a simple php forum software tutorial.
I may go a bit more in depth later on but hopefully this helps a few people out.
Enjoy!

Styled Demo: *none, I deleted the files ages ago, this is an ancient tutorial.
 
Nice mate good job, hopefully someone might find this useful in the near future ๐Ÿ™‚
 
Please post more <3 I love you....Ups got a keep it professional ๐Ÿ™‚
I am very impressed by your work sir. Please continue ๐Ÿ™‚
 
Connor said:
Shole said:
Please post more <3 I love you....Ups got a keep it professional ๐Ÿ™‚
I am very impressed by your work sir. Please continue ๐Ÿ™‚

Thanks haha.
This is like 2 years old, I made a whole system, if you want the source you can take a look.

http://litebbs.hourb.com/AeroBBv1LegacyBuild.zip
Yes please I am trying to learn how to create my own forum software for fun ๐Ÿ™‚ I want just a simple forum to set it up on some domain and just have fun with it ๐Ÿ™‚
 
Connor said:
Shole said:
Please post more <3 I love you....Ups got a keep it professional ๐Ÿ™‚
I am very impressed by your work sir. Please continue ๐Ÿ™‚

Thanks haha.
This is like 2 years old, I made a whole system, if you want the source you can take a look.

http://litebbs.hourb.com/AeroBBv1LegacyBuild.zip

You need to cast your values correctly, that whole system is at SQL vulnerability.

I glanced over your code and all I see it

Code:
$sql = "SELECT * FROM users WHERE users.uid = " . mysql_real_escape_string($_GET['id']) ."";

In every .php file...

Why are you not checking for negative numbers? casting as intval's? This whole system is asking for a mysql injection, why share code that is vulnerable?

I recommend you cast your values properly and check for negative numbers and other goodies before even thinking about making a forum software.
 
Awesome Tutorial but i think i saw a message board in a book of Larry Ullman
Something named "Advanced PHP"or "Php and mysql database"
 
This could be a good practice for some new to php, html and mysql. However, nice tutorial
 
Back
Top Bottom