Creating an Admin Panel
hey, this is my first tutorial so i hope you like it. The tutorial will teach / show you how to create an admin panel for your userysstem. i am using the levels:
6 = Admin
4 = Mod
2 = Validated user
I have tried to comment as much as possible!
So here goes
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
<?
session_start(); //allows session
include "config.php"; // Includes the config
if($logged[username] && $logged[userlevel] == 6)// Checks you are an admin
{
if($_GET[member])//gets the username
{
if (!$_POST[edit])//Checks if you are editing a user already
{
$user = mysql_query("SELECT * from members where username = '$_GET[member]'");// Selcts the right user from the database
$users = mysql_fetch_array($user);
echo "<form method=\"POST\">
<table width=\"100%\">
<tr>
<td align=\"right\" width=\"25%\">
User Level</td>
<td align=\"left\">
<select name=\"level\">
<option value=\"2\">User</option>
<option value=\"4\"> Mod </option>
<option value=\"6\"> Admin</option>
</select> </td>
</tr>
<tr>
<td align=\"right\" width=\"25%\">
Email</td>
<td align=\"left\">
<input type=\"text\" size=\"25\" maxlength=\"25\" name=\"email\"
value=\"$users[email]\"></td>
</tr>
<tr>
<td align=\"right\" width=\"25%\">Location</td>
<td align=\"left\">
<input size=\"25\" name=\"location\" value=\"$users[location]\"></td>
</tr>
<tr>
<td align=\"right\" width=\"25%\">Age</td>
<td align=\"left\">
<input size=\"25\" name=\"age\" value=\"$users[age]\"></td>
</tr>
<tr>
<td align=\"center\"></td>
<td align=\"left\">
<input type=\"submit\" name=\"edit\" value=\"Update\"></td>
</tr>
</table>
</form> <form method=\"POST\">
<table width=\"100%\">
<tr>
<td align=\"right\" width=\"25%\">
User Level</td>
<td align=\"left\">
<select name=\"level\">
<option value=\"2\">User</option>
<option value=\"4\"> Mod </option>
<option value=\"6\"> Admin</option>
</select> </td>
</tr>
<tr>
<td align=\"right\" width=\"25%\">
Email</td>
<td align=\"left\">
<input type=\"text\" size=\"25\" maxlength=\"25\" name=\"email\"
value=\"$users[email]\"></td>
</tr>
<tr>
<td align=\"right\" width=\"25%\">Location</td>
<td align=\"left\">
<input size=\"25\" name=\"location\" value=\"$users[location]\"></td>
</tr>
<tr>
<td align=\"right\" width=\"25%\">Age</td>
<td align=\"left\">
<input size=\"25\" name=\"age\" value=\"$users[age]\"></td>
</tr>
<tr>
<td align=\"center\"></td>
<td align=\"left\">
<input type=\"submit\" name=\"edit\" value=\"Update\"></td>
</tr>
</table>
</form>"; // Displays the form
}else{
$email = htmlspecialchars($_POST[email]);//removes all HTML
$age = htmlspecialchars($_POST[age]);//removes all HTML
$location = htmlspecialchars($_POST[location]);//removes all HTML
$level = htmlspecialchars($_POST[level]);//removes all HTML
echo "Thank you $logged[username], $_GET[member]'s Profile was updated!"; // Shows the message of your choice (feel free to change it)
$update = mysql_query("Update members set location = '$location', age = '$age', level = '$level', email = '$email' where username = '$_GET[member]'"); // updates the user
}
}else{
$adminuser = mysql_query("Select * from members order by username asc"); //Makes a list of all the users in alphabeticle order!
while($adminusers = mysql_fetch_array($adminuser))
{
echo "<a href='admin.php?member=$adminusers[username]'>$adminusers[username]</a>"; //Displayes the links to edit the user.
}
}
}else{
//If someone is trying to get onto this page without being an admin then they wont get through!
echo "Sorry, but only Admins may view this page. Please go back!";
}
?>
Well thats all i can think of at the moment, Any problems comment below! Also for admin only pages the code is
PHP Code
<?
session_start(); //allows session
include "config.php"; // Includes the config
if($logged[username] && $logged[userlevel] == 6)// Checks you are an admin
{ echo "Admin stuff here";
}else{
echo "Sorry only admins!";
}
?>
Hope this was a good tutorial!