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

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
1
2
3
4
5
6
7
8
9
10
<?
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!
MOD-Dan
Author:
Views:
4037
Rating:
Posted on Saturday 8th November 2008 at 09:06 PM
Dava
Dava
god knows just remove one of them
Posted on Saturday 8th November 2008 at 06:22 PM
shedh
shedh
Why is their two forms on the page?
Posted on Thursday 5th June 2008 at 05:22 AM
Adam981
Adam981
Well, im back with a new host and ive tryed this again, but it just doesnt update the userrs level or information.. and also theres to forms displayed
Posted on Saturday 3rd May 2008 at 03:05 AM
Adam98
Adam98
Ok well all the errors are fixed, just doesnt update the users information or rank.? Sigh:(
Posted on Saturday 3rd May 2008 at 02:41 AM
ShadowMage
ShadowMage
okay, or if you want you can send me a pm
Posted on Saturday 3rd May 2008 at 02:29 AM
Adam98
Adam98
Ok, ill give that a try.. host is being slow and stupid again. but thanks for the help, ill post and let u know if it worked.
Posted on Saturday 3rd May 2008 at 02:25 AM
ShadowMage
ShadowMage
Replace:
Code

<form method="POST">


With
Code

<form method="POST">
Posted on Saturday 3rd May 2008 at 02:23 AM
Adam98
Adam98
<?
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">
Posted on Saturday 3rd May 2008 at 02:21 AM
ShadowMage
ShadowMage
Alright, show me the line above them real quick.

Code

$user = mysql_query("SELECT * from members where username = '".$_GET[member]."'");// Selcts the right user from the database
Posted on Saturday 3rd May 2008 at 02:18 AM
Adam98
Adam98
$user = mysql_query("SELECT * from members where username = '$_GET[member]'");// Selcts the right user from the database
$users = mysql_fetch_array($user);