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

Tutortial system

Well this tutorial system is a little messed up but im sure it is well worth it! just so you know it does all come together in the end!
First off run this query in PHP my admin!
Code
CREATE TABLE `tutorials` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(225) NOT NULL,
`tutorial` text NOT NULL,
`approved` varchar(2) NOT NULL default '0',
`type` text NOT NULL,
`desc` text NOT NULL,
`views` varchar(20) NOT NULL default '1',
PRIMARY KEY (`id`)
) TYPE=MyISAM;

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
session_start
(); //allows session
include "config.php";
function 
bb2html($content){
$content nl2br($content);

$match = array(
'#[ b](.*?)#se'// Bold Tag;;Remove Spaces
'#[ i](.*?)#se'// Italic Tag;;Remove Spaces
'#[ u](.*?)#se'// Underlined Tag;;Remove Spaces
'#[ url=(.*?)](.*?)[/url]#se'// Url Tag;;Remove Spaces
'#[ code ](.*?)[/ code ]#se'// CODE Tag;;Remove Spaces
'#[ img](.*?)[/img]#se'// Image Tag;;Remove Spaces
'#[ php](.*?)[ /php]#se'// PHP Tag;;Remove Spaces
);

$replace = array(
"'<b>\1</b>'"// Bold
"'<i>\1</i>'"// Itlaic
"'<u>\1</u>'"//Underlined
"'<a href=\"\1\" target=\"_BLANK\">\2</a>'"// Url
"'
<style type=\"text/css\">
<!--
.style2 {font-size: 11}
-->
</style>
<table width=\"95%\" border=\"0\">
<tr>
<td bgcolor=\"#999999\"><b>Code</b></td>
</tr>
<tr>
<td bgcolor=\"#999999\"><span class=\"style2\">"
.highlight_string(stripslashes(str_replace('''''$1')), true)."</span></td> </tr>
</table>'"
// Url
"'<img border=\"0\" src=\"\1\">'"// Image
"'<style type=\"text/css\">
<!--
.style2 {font-size: 12}
-->
</style>
<table width=\"95%\" border=\"0\">
<tr>
<td bgcolor=\"#999999\"><b>PHP Code</b></td>
</tr>
<tr>
<td bgcolor=\"#999999\"><span class=\"style2\">"
.highlight_string(stripslashes(str_replace('''''$1')), true)."</span></td>
</tr>
</table>'"
);

return 
preg_replace($match$replace$content); // Replaces the bbcode array with the html array.
}
?>




Ok so now we have the bbcode next we have the submit tutorials page (addtut.php)
addtut.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
<?php
session_start
(); //allows session
include "config.php";
include(
"bbcode.php");
?>
<body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0">
<table border="1" width="100%" cellspacing="0" id="table1" style="border-width: 0px" cellpadding="0" height="16">
<tr>
<td style="border-style: none; border-width: medium" bgcolor="#3399ff" height="14"><b> <font face="Verdana" size="1" color="#FFFFFF">Submit a tutorial </font></b></td>
</tr>
</table><?
if ($logged[username])
{
// the user is logged in! We continue...
if (!$_POST[update])
{

echo(
"
<form method=\"POST\">
<table width=\"100\">
<tr>
<td align=\"left\" width=\"25%\">
Name of tutorial <br>
</td>
<td align=\"left\">
<input type=\"text\" size=\"25\" class='input' maxlength=\"500\" name=\"name\"></td>
</tr>
<tr>
<td align=\"left\" width=\"25%\">
Description <br>
</td>
<td align=\"left\">
<input type=\"text\" size=\"30\" class='input' maxlength=\"500\" name=\"desc\"></td>
</tr>
<tr>
<td align=\"left\" width=\"25%\">
catagory<br>
</td>
<td align=\"left\">
<select name=\"type\" class='button'>
<option value=\"PHP\">PHP</option>
<option value=\"HTML\">HTML</option>
<option value=\"Photoshop\">Photoshop</option>
<option value=\"CSS\">CSS</option>
<option value=\"Fireworks\">Fireworks</option>
<option value=\"MySQL\">MySQL</option>
<option value=\"Flash\">Flash</option>
<option value=\"Javascript\">Javascript</option>
<option value=\"Tips\">Site tips 'n' tricks</option>
</select></td>
</tr>
<tr>
<td align=\"left\" width=\"25%\">
Tutorial<br></td>
<td align=\"left\">
<textarea name=\"tutorial\" rows='15' class='input' cols='50'>Tutorial here</textarea></td>
</tr>
<td align=\"left\">
<input type=\"submit\" name=\"update\" class='button' value=\"Submit my tutorial!\"></td>
</tr>
</table>
</form>
"
);
}
else
{

$name $_POST[name];
$type $_POST[type];


$updatebadges mysql_query("INSERT INTO tutorials (`username`, `tutorial`, `approved`, `name`, `desc`, `type`) VALUES ('$logged[username]','$_POST[tutorial]','0','$name','$_POST[desc]','$type')");
echo(
"Thank you $logged[username], Your tutorial has been posted for admin review. Check back later to see if it has been approved!");
}
}
else
{
// They aren't logged in!
echo ("Sorry, you MUST be logged in to see this page!");
}
?>


Ok now the next bit is where we display the tutorials in one catagory so here goes (tutorial.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
<?

session_start
(); //allows session
include "config.php";
include(
"bbcode.php");

$cat $_GET[catagory];
echo(
"
<table border=\"1\" width=\"100%\" cellspacing=\"0\" id=\"table1\" style=\"border-width: 0px\" cellpadding=\"0\" height=\"16\">
<tr>
<td style=\"border-style: none; border-width: medium\" bgcolor=\"#3399ff\" height=\"14\"><b><font color=\"#FFFFFF\" size=\"1\" face=\"Verdana\">&nbsp;
$cat</font></b></td>
</tr>
</table>"
);
echo(
"<table width='100%' border='0' bgcolor='#33ccff'>
<tr>
<td width='60%' bgcolor='#33ccff'>Tutorial name and description</td>
<td width='10%' bgcolor='#33ccff'><div align='center'>#Views</div></td>
<td width='20%' bgcolor='#33ccff'><div align='center'>Author</div></td>
</tr>
</table><br>"
);

if (
$_GET[catagory])
{
$colour1 '#ffffff';
$colour2 '#d8d8d8';
$row_count 0;
$tutorials mysql_query("SELECT * from tutorials where type = '$_GET[catagory]' and approved = '1' order by id desc");
while (
$tutorial mysql_fetch_array($tutorials))
{

$row_colour = ($row_count 2) ? $colour1 $colour2;

echo (
"<table width='100%' border='0' bgcolor='$row_colour'>
<tr>
<td width='60%'><a href='tutorials.php?&catagory=
$_GET[catagory]&id=$tutorial[id]'> $tutorial[name]</a>
$user[desc]</td>
<td width='10%'><div align='center'>
$tutorial[views]</div></td>
<td width='20%'><div align='center'>
$tutorial[username]</div></td>
</tr>
</table>
"
);
$row_count++;
}
}
ELSE
{

echo (
"HMMMM how did you get here?");

}
?>

tutorials.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
<?
include("bbcode.php");

if (!
$_GET[catagory])
{
$getuser mysql_query("SELECT * from tutorials where type = '$_GET[catagory]' and approved = '1'");
while (
$user mysql_fetch_array($getuser))
{
echo (
"<a href='tutorials.php?catagory=$_GET[catagory]&name=$_GET[name]'>$user[name]</a>");
}
}
ELSE
{
$getuser mysql_query("SELECT * from tutorials where id = '$_GET[id]' and approved = '1'");
$usernum mysql_num_rows($getuser);
if (
$usernum == 0)
{
echo (
"You need to select a tutorial");
}
else
{
$profile mysql_fetch_array($getuser);
$content bb2html($profile[tutorial]);
echo (
"<table border=\"1\" width=\"100%\" cellspacing=\"0\" id=\"table1\" style=\"border-width: 0px\" cellpadding=\"0\" height=\"16\">
<tr>
<td style=\"border-style: none; border-width: medium\" bgcolor=\"#3399ff\" height=\"14\"><b><font color=\"#FFFFFF\" size=\"1\" face=\"Verdana\"><b>
$profile[name]</b> - <a href='members?user=$profile[username]'><font color='#FFFFFF'>$profile[username] - ");
if(
$logged[username] && $logged[userlevel] == 6){

?>
[<a href="mtut.php?act=tedit&tid=<? echo ("$profile[id]"); ?>">Edit</a>]
[<a href="mtut.php?act=tdel&tid=<? echo("$profile[id]"); ?>">Delete</a>]
<?
}
echo(
"
</font></a></font></b></td>
</tr>
</table>

<br> 
$content");
$views=stripslashes($profile['views']);

$views++;
mysql_query("UPDATE `tutorials` SET views='$views' WHERE id = '$profile[id]'");

}
}
?>

Ok so now we have add tutorial, view tutorials in catagory now we need view the tutorials...(tutorials.php)
Code

<?
include("bbcode.php");

if (!$_GET[catagory])
{
$getuser = mysql_query("SELECT * from tutorials where type = '$_GET[catagory]' and approved = '1'");
while ($user = mysql_fetch_array($getuser))
{
echo ("<a href='tutorials.php?catagory=$_GET[catagory]&name=$_GET[name]'>$user[name]</a><br />");
}
}
ELSE
{
$getuser = mysql_query("SELECT * from tutorials where id = '$_GET[id]' and approved = '1'");
$usernum = mysql_num_rows($getuser);
if ($usernum == 0)
{
echo ("You need to select a tutorial");
}
else
{
$profile = mysql_fetch_array($getuser);
$content = bb2html($profile[tutorial]);
echo ("<table border="1" width="100%" cellspacing="0" id="table1" style="border-width: 0px" cellpadding="0" height="16">
<tr>
<td style="border-style: none; border-width: medium" bgcolor="#3399ff" height="14"><b><font color="#FFFFFF" size="1" face="Verdana"><b>$profile[name]</b> - <a href='members?user=$profile[username]'><font color='#FFFFFF'>$profile[username] - ");
if($logged[username] && $logged[userlevel] == 6){

?>
[<a href="mtut.php?act=tedit&tid=<? echo ("$profile[id]"); ?>">Edit</a>]
[<a href="mtut.php?act=tdel&tid=<? echo("$profile[id]"); ?>">Delete</a>]
<?
}
echo("
</font></a></font></b></td>
</tr>
</table>

<br> $content");
$views=stripslashes($profile['views']);

$views++;
mysql_query("UPDATE `tutorials` SET views='$views' WHERE id = '$profile[id]'");

}
}
}
}
}
?>

Next we have the mtut.php (which allows admins to edit tutorials) PLEASE keep it as mtut.php else the links will not work!
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
<?php
if($logged[username] && $logged[userlevel] == 6){

switch (
$_GET['act']) { // Get action

case "tedit"// First action m
$id $_GET['tid']; // We add slashes for security purposes

if ($_POST['Submit']) { // If the form was submitted we check it
$post = ($_POST['post']); // Clean the edited tutorial
if (empty($post)) { // Check to see if the user has anything
exit("You gotta type something. <a href='".$_SERVER['REQUEST_URI']."'>Back?</a>"); // Error go back?
// Close if
mysql_query("UPDATE `tutorials` SET tutorial = '$post' WHERE id = '$id'"); // Update the new post into the database
echo "Tutorial Updated. "// Let user know we updated and for them to go back to the post
} else { // Now we show the form if it hasn't been submitted
$q mysql_fetch_array(mysql_query("SELECT * FROM `tutorials` WHERE id = '$id'")); //Now grab the post from database
$post = ($q['tutorial']); // Clean out post
echo ("
<form method=\"post\">
Post:
<textarea name=\"post\" class='input' cols=\"50\" rows=\"10\">
$post </textarea>
<input type=\"submit\" class='button' name=\"Submit\" value=\"Update\" />
</form>
"
); // End echo
}
break;
case 
"tdel";
$id $_GET['tid'];
if (empty(
$id) | !is_numeric($id)) {
exit (
"Invalid ID given.");
// All the same stuff up there
$q mysql_fetch_array(mysql_query("SELECT * FROM `tutorials` WHERE `id` = '$id'")); // First we need the post id from the table tutorial
$pid $q['id']; // Change it to $pid
mysql_query("DELETE FROM `tutorials` WHERE `id` = '$id'");

echo (
"Tutorial deleted!!"); // Let user know tutorial was deleted
break;
}
}else{
echo 
"<b>Error</b>: You Do Not Have Access To This File"// no access
//end level check
?>

So now we need to make the page where admins see all the tutorials to be approved (atut.php)
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?
if($logged[username] && $logged[usrelevel] == 6)
{
echo(
'<table border="1" width="100%" cellspacing="0" id="table1" style="border-width: 0px" cellpadding="0" height="16">
<tr>
<td style="border-style: none; border-width: medium" bgcolor="#3399ff" height="14"><b><font color="#FFFFFF" size="1" face="Verdana">Tutorials to be approved</font></b></td>
</tr>
</table><br>'
);
$getuser mysql_query("SELECT * from tutorials where approved = '0'");
while (
$user mysql_fetch_array($getuser))
{
// gets all the users information.
echo ("<a href='index.php?page=apptut&id=$user[id]'>$user[name] - $user[type]</a>");
}
}else{
echo(
"sorry only admins here please");
}
?>

ok now last but not least we need the admin approval. (apptut.php) *NOTE* that this page does something different to atut.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
<?
include("bbcode.php");
if(
$logged[username] && $logged[userlevel] == 6)
{
if(!
$_POST[update]) {
$getuser mysql_query("SELECT * from tutorials where id = '$_GET[id]'");
$profile mysql_fetch_array($getuser);
$content bb2html($profile[tutorial]);
echo (
'Tutorial name:<b>$profile[name]</b></center>
BY: $profile[username]
Catagory - $profile[type]
Tutorial: $content<br><br>
<form method="POST">
Approved? <select name="app" class=\'button\'>
<option value="1">Approve</option>
<option value="2">Decline</option>
</select>
<input type="submit" name="update" class=\'button\' value="Approve/Decline">
</form>'
);
# The Edit A Badge Form

}else{
# The Form Has Been Submitted

$updatebadge mysql_query("UPDATE tutorials SET `approved` = '$_POST[app]' WHERE id = '$_GET[id]'");
echo(
"The tutorial has been Sorted!");
# Updates Badge
}
}
else{
echo(
" Sorry only admins can be here");
}
?>
Well that concludes. i hope i havent missed anything out! Sorry that it was a bit of a ong tutorial that i could of cut short if i realy tried to. I hope this helps a lot of people that have been requesting tutorial also just one last thing. Please the following code anywhere you like in your usersystem!
Code

<?
if($logged[username] && $logged[userlevel] == 6) {
$tut = mysql_query("select * from tutorials where approved = '0'");
$tut = mysql_num_rows($tut);
echo("<a href='atut.php'> Sort tutorials ($tut) ")
}else{
echo(" ");
}
?>

I hope this helps some people!
MOD-Dan
Author:
Views:
3396
Rating:
Posted on Sunday 23rd August 2015 at 06:24 AM
xensor
xensor
after i am done with the code i will post the new code so it be more understanding that way new people that are looking for ways to add a tutorial system can.
Posted on Sunday 23rd August 2015 at 06:24 AM
xensor
xensor
this tutorial is so unorganized and badly written. its so confusing that myself can barely make sense of it.

the 2 tutorial pages are like wow. so many $_GETs to get results when really one should be about showing all the tutorials and then clicking on a link to show a certain record or section.

but one of em isn't that way.
Posted on Sunday 8th June 2008 at 08:59 PM
Adam981
Adam981
Well in apptut.php it displays

Tutorial name:$profile[name]
BY: $profile[username] Catagory - $profile[type] Tutorial: $content

mtut.php doesnt display anything


atut.php link doesnt work


addtut.php says it needs to be apprioved but doesnt go into the database
Posted on Sunday 8th June 2008 at 05:54 PM
Diablosblizz
Diablosblizz
Adam, some more information other than it doesn't work would be helpful.
Posted on Sunday 8th June 2008 at 03:32 PM
Adam981
Adam981
Alright well i added all my code and what not, but this just doesnt want to work.. things that dont work are, atut.php apptut.php mtut.php

can someone either msg me and help me fix it or maybe update the codes? either way please let me know!
Posted on Tuesday 3rd June 2008 at 07:39 PM
ShadowMage
ShadowMage
Hey guys, use the Highlighted code. the person who edited added 2 of one file. I'll go fix.
Posted on Tuesday 3rd June 2008 at 07:38 PM
Adam981
Adam981
Nathan u should really read the comments made by other users theres a fix for ur error like 3 comments up lol..

PHP Code
1
echo("<table border="1" width="100%" cellspacing="0" id="table1" style="border-width: 0px" cellpadding="0" height="16">
Posted on Thursday 17th April 2008 at 06:57 AM
Nathan
Nathan
Parse error: syntax error, unexpected T_LNUMBER in /home/rdlegend/public_html/tut/tutorials.php on line 24
Posted on Thursday 17th April 2008 at 06:47 AM
Nathan
Nathan
error in app tut

Setup name:" . $profile . " BY: $tutorials[username] Catagory - " . $profile . " Setup: " . $content . "
Posted on Friday 11th April 2008 at 09:30 PM
DanielXP
DanielXP
Test you need the blackslash before the quotes inside an echo using the same quotes.

PHP Code
1
echo("<table border="1" width="100%" cellspacing="0" id="table1" style="border-width: 0px" cellpadding="0" height="16">


Its weird because the tutorial has the backslashes in so it should work.