Forgot Password / Register
Site Statistics
Total Members: 520
Total Tutorials: 242
Newsest User: 8884244477
Todays Unique Hits: 365
0 Users 12 Guests Online

Forum-Add on For Usersystem

Forum add-on tutorial. Also an avatar editor. awesome stuff. I'll explain everything at the end.
Our mysql database queries. without these the code doesn't work.



Code

-- --------------------------------------------------------

CREATE TABLE `forum_category` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(225) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM;

-- --------------------------------------------------------

CREATE TABLE `forum_posts` (
`id` int(10) NOT NULL auto_increment,
`message` varchar(225) NOT NULL default '',
`poster` varchar(225) NOT NULL default '',
`thr_id` int(10) NOT NULL default '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM;

-- --------------------------------------------------------

CREATE TABLE `forum_thread` (
`id` int(11) NOT NULL auto_increment,
`title` varchar(225) NOT NULL default '',
`message` varchar(225) NOT NULL default '',
`poster` varchar(225) NOT NULL default '',
`top_id` int(10) NOT NULL default '0',
`thr_id` int(10) NOT NULL default '0',
`sticky` varchar(225) NOT NULL default 'No',
`locked` varchar(225) NOT NULL default 'No',
PRIMARY KEY (`id`)
) ENGINE=MyISAM;

-- --------------------------------------------------------

CREATE TABLE `forum_topic` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(225) NOT NULL default '',
`description` varchar(225) NOT NULL default '',
`cat_id` int(10) NOT NULL default '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM;

-- --------------------------------------------------------

ALTER TABLE `members` ADD `avatar` VARCHAR( 225 ) NOT NULL ;


First page save as forum_admin.php
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
session_start
();
include 
"config.php";
if(
$logged[username] && $logged[userlevel] == 6)
{
switch(
$_GET[page])
{
default:
echo (
"Admin Panel Choose Feature.<br>
<a href='?page=addcategory'>Add Category</a>
<br>
<a href='?page=deletecategory'>Delete Category</a>
<br>
<a href='?page=addtopic'>Add Topic</a>
<br>
<a href='?page=deletetopic'>Delete Topic</a>
"
);
break;

case 
'addcategory':
echo (
"
<form method='POST' action='?page=insertcategory'>
<table width='100%'>
<tr>
<td align='right' width='25%'>New Category Name</td>
<td align='left'>
<input size='25' name='category'></td>
</tr>
<tr>
<td align='center'></td>
<td align='left'>
<input type='submit' name='submit' value='Update'></td>
</tr>
</table>
</form>
"
);
break;

case 
'insertcategory':
$category strip_tags(htmlspecialchars($_POST[category]));
$insert mysql_query("INSERT INTO `forum_category` (`name`) VALUES ('$category')");
echo (
"New Category Created. <br><a href='forum_admin.php'>Go back.</a>");
break;

case 
'deletecategory':
echo (
"
<form method='POST' action='?page=removecategory'>
<table width='100%'>
<tr>
<td align='right' width='25%'>Delete Category</td>
<td align='left'>
<select name='category'>
"
);
$fetch mysql_query("SELECT * FROM `forum_category`"); //fetches all the forum categories from the database and displays them
while ($category mysql_fetch_array($fetch))
{
echo (
"<option value='$category[name]'>$category[name]</option>");
}
echo (
"
</select>
</td>
</tr>
<tr>
<td align='center'></td>
<td align='left'>
<input type='submit' name='submit' value='Update'></td>
</tr>
</table>
</form>
"
);
break;

case 
'removecategory':
$category strip_tags(htmlspecialchars($_POST[category]));
$insert mysql_query("DELETE FROM `forum_category` WHERE name = '$category'");
echo (
"Category Deleted.<br><a href='forum_admin.php'>Go back.</a>");
break;

case 
'addtopic':
echo (
"
<form method='POST' action='?page=inserttopic'>
<table width='100%'>
<tr>
<td align='right' width='25%'>New Topic Name</td>
<td align='left'>
<input size='25' name='topic'></td>
</tr>
<tr>
<td align='right' width='25%'>Description</td>
<td align='left'>
<input size='25' name='description'></td>
</tr>
<tr>
<td align='right' width='25%'>Under Category</td>
<td align='left'>
<select name='cid'>
"
);
$fetch mysql_query("SELECT * FROM `forum_category`");
while (
$category mysql_fetch_array($fetch))
{
echo (
"<option value='$category[id]'>$category[name]</option>");
}
echo (
"
</select>
</td>
</tr>
<tr>
<td align='center'></td>
<td align='left'>
<input type='submit' name='submit' value='Update'></td>
</tr>
</table>
</form>
"
);
break;

case 
'inserttopic':
$description strip_tags(htmlspecialchars($_POST[description]));
$topic strip_tags(htmlspecialchars($_POST[topic]));
$cid = (int) htmlspecialchars($_POST[cid]);
$insert mysql_query("INSERT INTO `forum_topic` (`name`, `cat_id`, `description`) VALUES ('$topic', '$cid', '$description')");
echo (
"New Category Created. Redirecting you...<meta http-equiv='refresh' content='2;url=forum_admin.php'>");
break;

case 
'deletetopic':
echo (
"
<form method='POST' action='?page=removetopic'>
<table width='100%'>
<tr>
<td align='right' width='25%'>Delete Topic</td>
<td align='left'>
<select name='topic'>
"
);
$fetch mysql_query("SELECT * FROM `forum_topic`");
while (
$topic mysql_fetch_array($fetch))
{
echo (
"<option value='$topic[name]'>$topic[name]</option>");
}
echo (
"
</select>
</td>
</tr>
<tr>
<td align='center'></td>
<td align='left'>
<input type='submit' name='submit' value='Update'></td>
</tr>
</table>
</form>
"
);
break;

case 
'removetopic':
$topic htmlspecialchars(strip_tags($_POST[topic]));
$insert mysql_query("DELETE FROM `forum_topic` WHERE name = '$topic'");
echo (
"Category Deleted. Redirecting you...<meta http-equiv='refresh' content='2;url=forum_admin.php'>");
break;
}
}
?>


Second page as forum_mod.php
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
session_start
();
include 
"config.php";
echo (
"<link rel='stylesheet' href='style.css'>");
if(
$logged[username] && $logged[userlevel] == ||$logged[userlevel] == 6)
{
switch(
$_GET[page])
{
default:
echo (
"Can't access this file directly.");
break;

case 
'sticky':
$id = (int) htmlspecialchars($_GET[id]);
$fetch mysql_query("SELECT * FROM `forum_thread` WHERE `id` = '$id'");
$thread mysql_fetch_array($fetch);
if (
$thread[sticky] == Yes)
{
echo (
"This has already been sticked. <br><a href='javascript: history.go(-1)'>Go back.</a>");
}
else
{
$update mysql_query("UPDATE `forum_thread` SET `sticky` = 'Yes' WHERE `id` = '$id'");
echo (
"Thread has been stickied. <br><a href='javascript: history.go(-1)'>Go back.</a>");
}
break;

case 
'lock':
$id = (int) htmlspecialchars($_GET[id]);
$fetch mysql_query("SELECT * FROM `forum_thread` WHERE `id` = '$id'");
$thread mysql_fetch_array($fetch);
if (
$thread[locked] == Yes)
{
echo (
"This has already been locked.<br><a href='javascript: history.go(-1)'>Go back.</a>");
}
else
{
$update mysql_query("UPDATE `forum_thread` SET `locked` = 'Yes' WHERE `id` = '$id'");
echo (
"Thread has been locked.<br><a href='javascript: history.go(-1)'>Go back.</a>");
}
break;

case 
'delete':
$id = (int) htmlspecialchars($_GET[id]);
$fetch mysql_query("DELETE FROM `forum_posts` WHERE `id` = '$id'");
echo (
"Post has been deleted.<br><a href='javascript: history.go(-1)'>Go back.</a>");
break;
}
}
?>


Third page as forum.php
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<?php
session_start
();
include (
"config.php");
include (
"bbcode.php");

echo (
"<link rel='stylesheet' href='style.css'>");
if(
$logged[username])
{
switch(
$_GET[page])
{
default:
echo (
"<table width='100%' cellpadding='0'>");
$fetch1 mysql_query("SELECT * FROM `forum_category`");
while (
$category mysql_fetch_array($fetch1))
{
echo (
"<tr>
<td id='mains'><b>
$category[name]<b><br></td>
</tr>
"
);
$fetch2 mysql_query("SELECT * FROM `forum_topic` WHERE `cat_id` = '$category[id]'");
while (
$topic mysql_fetch_array($fetch2))
{
echo (
"<tr>
<td id='fields'><a href='?page=forum&id=
$topic[id]'>$topic[name]</a><br><i>$topic[description]</i></td>
</tr>
"
);
}
}
echo (
"</table>");
$rows mysql_num_rows($fetch1);
if (
$rows == 0)
{
echo (
"<center><b>Forum is Empty<b></center>");
}
break;

case 
'forum':
echo (
"<table width='100%' cellpadding='0'>");
$fetch1 mysql_query("SELECT * FROM `forum_topic` WHERE `id` = '$_GET[id]'");
$topic mysql_fetch_array($fetch1);
echo (
"<tr><td id='mains'><b>$topic[name]</b> - <a href='?page=newthread&id=$_GET[id]'>New Thread</a></td><td id='mains'><b>Thread starter</b></td></tr>");

$fetch2 mysql_query("SELECT * FROM `forum_thread` WHERE `thr_id` = '$_GET[id]' ORDER BY `sticky` DESC");
while (
$thread mysql_fetch_array($fetch2))
{
$threadtitle "$thread[title]";
$bbctt1 BBCODE($threadtitle);
if(
$thread[sticky] == Yes)
{
echo (
"<tr><td id='fields'><a href='?page=forumdisplay&id=$thread[id]'><b>Sticky:</b> $bbctt1</a></td><td id='fields'>$thread[poster]</td></tr>");
}
else
{
echo (
"<tr><td id='fields'><a href='?page=forumdisplay&id=$thread[id]'>$bbctt1</a></td><td id='fields'>$thread[poster]</td></tr>");
}
}
echo (
"</table>");
break;

case 
'forumdisplay':
echo (
"<table width='100%' cellpadding='0'>");
$fetch1 mysql_query("SELECT * FROM `forum_thread` WHERE `id` = '$_GET[id]'");
$thread mysql_fetch_array($fetch1);

$fetch3 mysql_query("SELECT * FROM `members` WHERE `username` = '$thread[poster]'");
$threadavatar mysql_fetch_array($fetch3);

$threadtitle "$thread[title]";
$bbctt2 BBCODE($threadtitle);

$threadmessage "$thread[message]";
$bbctm BBCODE($threadmessage);

echo (
"<tr>
<td id='mains'>&nbsp;</td>"
);
if(
$thread[sticky] == Yes)
{
echo (
"<td id='mains'><b>Sticky:</b> $bbctt2</td></tr>");
}
else
{
echo (
"<td id='mains'><b>$bbctt2</b></td></tr>");
}
echo (
"<tr>
<td id='mains' align='center' width='120'><a href=javascript:void(window.open('members.php?user=
$thread[poster]','client','status=1,width=400,height=250,top=60,left=60'))>$thread[poster]</a><br>
<img src='
$threadavatar[avatar]'>
"
);
if (
$logged[userlevel] == '4' || $logged[userlevel] == '6')
{
echo (
"<br><a href='forum_mod.php?page=lock&id=$thread[id]'>Lock</a> - <a href='?page=editthread&id=$thread[id]'>Edit</a> - <a href='forum_mod.php?page=sticky&id=$thread[id]'>Sticky</a>");
}
if (
$thread[poster] == $logged[username])
{
echo (
"<br><a href='?page=editthread&id=$thread[id]'>Edit Post</a>");
}
echo (
"
</td><td id='mains' align='left' valign='top'>
$bbctm</td></tr>");

$fetch2 mysql_query("SELECT * FROM `forum_posts` WHERE `thr_id` = '$_GET[id]'");
while (
$posts mysql_fetch_array($fetch2))
{
$postsmessage "$posts[message]";
$bbcpm BBCODE($postsmessage);

$fetch4 mysql_query("SELECT * FROM `members` WHERE `username` = '$posts[poster]'");
$postsavatar mysql_fetch_array($fetch4);

echo (
"<tr>
<td id='fields' align='center'>
$posts[poster]
<br>
<img src='
$postsavatar[avatar]'>
"
);
if (
$logged[userlevel] == '4' || $logged[userlevel] == '6')
{
echo (
"<br><a href='forum_mod.php?page=delete&id=$posts[id]'>Delete</a> - <a href='?page=editpost&id=$posts[id]'>Edit</a>");
}
if (
$logged[username] == $posts[poster])
{
echo (
"<br><a href='?page=editpost&id=$posts[id]'>Edit Post</a>");
}
echo (
"
</td>
<td id='fields' align='left' valign='top'>
$bbcpm</td>
</tr>"
);
}
if (
$thread[locked] == 'Yes')
{
echo (
"<tr><td id='fields'>&nbsp;</td><td id='fields' valign='top'><b>This Thread is locked.</b></td></tr>");
}
else
{
echo (
"
<tr>
<td id='fields'><center>Quick Reply</center></td>
<form method='POST' action='?page=addreply'>
<td id='fields'><textarea name='message' rows='8' cols='30'></textarea><br>
<input type='submit' name='submit' value='Post'>
<input type='hidden' name='id' value='
$_GET[id]'></td>
</tr>
</form>
"
);
}
break;

case 
'addreply':
$id htmlspecialchars($_POST[id]);
$message htmlspecialchars($_POST[message]);
$insert mysql_query("INSERT INTO `forum_posts` (`message`, `poster`, `thr_id`) VALUES ('$message', '$logged[username]', '$id')");
echo (
"Thanks for your reply. <br><a href='javascript: history.go(-1)'>Go back.</a>");
break;

case 
'newthread':
echo (
"<form method='POST' action='?page=addthread'>
<table width='100%'>
<tr>
<td>Title</td>
<td><input type='text' name='title'></td>
</tr>
<tr>
<td>Message</td>
<td><textarea name='message' rows='10' cols='40'></textarea></td>
</tr>
<tr>
<td></td>
<td><input type='submit' name='submit' value='Post'>
<input type='hidden' name='id' value='
$_GET[id]'></td>
</tr>
</table>
</form>
"
);
break;

case 
'addthread':
$id htmlspecialchars($_POST[id]);
$query mysql_query("SELECT * FROM `forum_thread` WHERE `id` = '$id'");
$array mysql_fetch_array($query);
if (
$array[locked] == Yes)
{
echo (
"You can't post that in here.");
}
else
{
$title htmlspecialchars($_POST[title]);
$message htmlspecialchars($_POST[message]);
$insert mysql_query("INSERT INTO `forum_thread` (`title`, `message`, `poster`, `thr_id`) VALUES ('$title', '$message', '$logged[username]', '$id')");
echo (
"Your thread has been added.<br><a href='javascript: history.go(-2)'>Go back.</a>");
}
break;

case 
'editthread':
$fetch mysql_query("SELECT * FROM `forum_thread` WHERE `id` = '$_GET[id]'");
$thread mysql_fetch_array($fetch);
if (
$logged[username] == $thread[poster] || $logged[userlevel] == 6)
{
echo (
"
<form method='POST' action='?page=updatethread'>
<table width='100%'>
<tr>
<td>Title</td>
<td><input type='text' name='title' value='
$thread[title]'></td>
</tr>
<tr>
<td>Message</td>
<td><textarea name='message' rows='10' cols='40'>
$thread[message]</textarea></td>
</tr>
<tr>
<td></td>
<td><input type='submit' name='submit' value='Post'>
<input type='hidden' name='id' value='
$_GET[id]'></td>
</tr>
</table>
</form>
"
);
}
else
{
echo (
"You can't edit this thread.");
}
break;

case 
'updatethread':
$id htmlspecialchars($_POST[id]);
$query mysql_query("SELECT * FROM `forum_thread` WHERE `id` = '$id'");
$array mysql_fetch_array($query);
if (
$array[poster] == $logged[username] || $logged[userlevel] == 6)
{
$title htmlspecialchars($_POST[title]);
$message htmlspecialchars($_POST[message]);
$query mysql_query("UPDATE `forum_thread` SET `title` = '$title', `message` = '$message' WHERE `id` = '$id'");
echo (
"Thread has been updated.<br><a href='javascript: history.go(-2)'>Go back.</a>");
}
else
{
echo (
"You can't edit this thread.");
}
break;

case 
'editpost':
$fetch mysql_query("SELECT * FROM `forum_posts` WHERE `id` = '$_GET[id]'");
$post mysql_fetch_array($fetch);
if (
$logged[username] == $post[poster] || $logged[userlevel] == 6)
{
echo (
"
<form method='POST' action='?page=updatepost'>
<table width='100%'>
<tr>
<td>Message</td>
<td><textarea name='message' rows='10' cols='40'>
$post[message]</textarea></td>
</tr>
<tr>
<td></td>
<td><input type='submit' name='submit' value='Post'>
<input type='hidden' name='id' value='
$_GET[id]'>
</td>
</tr>
</table>
</form>
"
);
}
else
{
echo (
"You can't edit this post.");
}
break;

case 
'updatepost':
$id htmlspecialchars($_POST[id]);
$query mysql_query("SELECT * FROM `forum_thread` WHERE `id` = '$id'");
$array mysql_fetch_array($query);
if (
$array[poster] == $logged[username] || $logged[userlevel] == 6)
{
$message htmlspecialchars($_POST[message]);
$update mysql_query("UPDATE `forum_posts` SET `message` = '$message' WHERE `id` = '$id'");
echo (
"Thread updated.<br><a href='javascript: history.go(-2)'>Go back.</a>");
}
else
{
echo (
"You can't edit this thread.");
}
break;
}
}
?>


Fourth page as bbcode.php

PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?
function BBCODE($content){ //define the function of bbcode
$content nl2br($content); //replaces returns with br's
$match = array(
'#\[b\](.*?)\[\/b\]#se',
'#\[i\](.*?)\[\/i\]#se',
'#\[u\](.*?)\[\/u\]#se',
'#\[url=(.*?)\](.*?)\[\/url\]#se',
'#\[url\](.*?)\[\/url\]#se',
'#\[img\](.*?)\[\/img\]#se',
'#\[code\](.*?)\[\/code\]#se',
'#\[php\](.*?)\[\/php\]#se',
'#\[print\](.*?)\[\/print\]#se'
); //codes used in posts
$replace = array(
"'<b>\\1</b>'",
"'<i>\\1</i>'",
"'<u>\\1</u>'",
"'<a href=\"\\1\" target=\"_BLANK\">\\2</a>'",
"'<a href=\"\\1\" target=\"_BLANK\">\\1</a>'",
"'<img border=\"0\" src=\"\\1\">'",
"'<u><b>Code:</b></u>
<div style=\"border: 1px dotted #000000; background-color: #CCCCCC; overflow: auto;\">
'.highlight_string(stripslashes(str_replace('', '', '$1')), true).'</div>'"
,
"'<u><b>PHP Code:</b></u>
<div style=\"border: 1px dotted #000000; background-color: #CCCCCC; overflow: auto;\"> '.highlight_string(stripslashes(str_replace('', '', '$1')), true).'</div>'"
,
"'<u><b>Print Out:</b></u>
<div style=\"border: 1px dotted #000000; background-color: #CCCCCC; overflow: auto;\">
'.highlight_string(stripslashes(str_replace('', '', '$1')), true).'</div>'"
); //replacements
return preg_replace($match$replace$content); //match, and replace
//end the function
?>


Fifth page as avatar.php
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
include "config.php";
if(
$logged[username])
{
switch(
$_GET[page])
{
default:
echo (
"
<form action='?page=upload' enctype='multipart/form-data' method='POST'>
<table border='1'>
<tr>
<td>Avatar</font></td>
<td><input type='file' size='7' name='avatar' id='avatar'></td>
</tr>
<tr>
<td colspan='2' align='center'><input type='submit' name='submit' value='Upload'></td>
</tr>
</table>
</form>
"
);
break;

case 
'upload':
$filename $_FILES["avatar"]["name"];
$tmp_name $_FILES["avatar"]["tmp_name"];

$avatar "images/$filename";
$username $logged[username];
if (
move_uploaded_file($tmp_name"images/".$filename))
{
$query mysql_query("UPDATE `members` SET `avatar` = '$avatar' WHERE `username` = '$logged[username]'");
echo (
"File uploaded $avatar$username");
}
else
{
die(
"Uploading file Failed.");
}
break;
}
}
?>


Last page save as style.css
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#mains
{
background-color: #C0C0C0;
font-family: Verdana;
font-size: 8pt;
color: #000000;
border-color: #000000;
border-style: solid;
border-width: thin;
padding: 0px;
}
#fields
{
background-color: #FFFFFF;
font-family: Verdana;
font-size: 8pt;
color: #000000;
border-color: #000000;
border-style: solid;
border-width: thin;
padding: 0px;
}
body
{
background-color: #FFFFFF;
font-family: Verdana;
font-size: 8pt;
color: #000000;
padding: 0px;
}
td
{
background-color: #FFFFFF;
font-family: Verdana;
font-size: 8pt;
color: #000000;
padding: 0px;
}
a:link
{
color: #000000;
text-decoration: none;
font-family: Verdana;
font-size: 8pt;
}
a:visited
{
text-decoration: none;
color: #000000;
font-family: Verdana;
font-size: 8pt;
}
a:hover
{
text-decoration: underline;
color: #000000;
font-family: Verdana;
font-size: 8pt;
}
a:active
{
text-decoration: none;
color: #000000;
font-family: Verdana;
font-size: 8pt;
}


Okay I'll start defining. It's a big tutorial so bear with me I'll generalise to make it smaller.

Code

<?php
session_start();
include "config.php";

This code always at the top of our page turns on PHP, starts the session and then includes our database connection file.

Code

switch($_GET[page])
{

Used in all the pages it makes it so the url can be ?page= something.

Code

default:
break;

This comes right after the switch code, anything in between wil be displayed if the url is incorrect eg. ?page=formu would show the default page.

Code

case '':
break;

For example if inbetween the two '' said fries it would allow the url to go to ?page=fries and everything in between case '': and break; would be displayed.

Code

<form method='POST' action='?page='>
</form>

In all pages of the coding forms are used alot. All of them will have at least this in common. action tells us where to post it to. like an email except its a page url. Any values inbetween these two tags will be sent.

Code

if ($logged[username])
{

This makes sure the user is logged in.

Code


if ($logged[username] && $logged[userlevel] == 4 || $logged[userlevel] == 6)
{

This makes sure the user is logged in and makes sure the user is either level 4 or level 6. seen alot throughout the codes.

Our CSS coding is used so we dont have to put the html coding all throughout the code.
Code

<td id=''></td>

in the '' would be defined with one of the CSS headers and as stated before saves us writing it in all the time.

Thats it for the generalised coding explanation and the tutorial. Hope you like it.
Edit: New tutorial as old one had many errors.
SkillMaster
Views:
6598
Rating:
Posted on Friday 22nd August 2008 at 01:05 PM
dtnet
dtnet
You have to make yourselves a admin, by editing in the phpmyadmin. Then you have to add a category and a topic, in forum_admin.php. Then you'll see something in forum.php
Posted on Friday 22nd August 2008 at 11:08 AM
MonDieu72
MonDieu72
Hello!
Im a beginner so my knowledge about php is catastrophically close to zero so... after following this tut all I get are blank white pages. Can someone help me? I got the usersystem up and running (at www.cadavericecream.com) wasnt that hard tnx very much for that one :)
Posted on Wednesday 20th August 2008 at 04:41 PM
dtnet
dtnet
What?
Posted on Wednesday 20th August 2008 at 04:28 PM
Vic Vance
Vic Vance
Do you know what Please help I need this forum.

thngs not working

catogary
forum
new thread
discriptiob
Posted on Tuesday 15th July 2008 at 06:09 PM
UrbanTwitch
UrbanTwitch
Doesn't work =(
Posted on Tuesday 15th July 2008 at 06:06 PM
UrbanTwitch
UrbanTwitch
All I see is a blank on forum.php :(
Posted on Wednesday 18th June 2008 at 05:04 PM
dtnet
dtnet
I tried to use the forum from the forum tutorial. But when I'm adding a new thread, nothing appears. It says that I've added a new thread, but it doesn't come up in teh forum


Remove - To long and not in code tags.
Posted on Tuesday 10th June 2008 at 06:49 PM
Adam981
Adam981
is there anyway to make the avatar resize to a size that u want? that way when ppl upload there all the same size?
Posted on Thursday 5th June 2008 at 10:48 PM
Brandon
Brandon
When I post a thread,edit,sticky,delete I get logged out PLZ give me a fix I believe the error is in this line

default:
echo ("<table width='100%' cellpadding='0'>");
$fetch1 = mysql_query("SELECT * FROM `forum_category`");
while ($category = mysql_fetch_array($fetch1))
{
echo ("<tr>
<td id='mains'><b>$category[name]<b><br></td>
</tr>
");
$fetch2 = mysql_query("SELECT * FROM `forum_topic` WHERE `cat_id` = '$category[id]'");
while ($topic = mysql_fetch_array($fetch2))
{
echo ("<tr>
<td id='fields'><a href='?page=forum&id=$topic[id]'>$topic[name]</a><br><i>$topic[description]</i></td>
</tr>
");
}
}
Posted on Wednesday 30th April 2008 at 03:07 PM
Dalez
Dalez
Vinniiee i also got that problem, and i never actually fixed it.