Creating the Admin Script for a PHP/MySQL Blogging System - The Admin script (Page 2 of 4 )
As stated before, all the work will be done from one page, which I’ve called main.php. This page can only be accessed from the login page, and then only if you are registered as an admin. You can of course change the point of access to the main blog script if you wish. It is only written in this way because it was more practical from the article's point of view.
The page itself has the following code, in addition to the usual HTML formatting:
<?
if(isset($_GET['action'])){
$action=$_GET['action'];
switch($action)
{
Case "listusers";
listusers();
break;
Case "listmsgs";
listmsgs();
break;
Case "listcat";
listcat();
break;
Default;
break;
}
}else{
echo '<center><table>
<tr>
<td align="center"> <font size="5" color="#00000">MyBlog Admin
Control Centre</font> <br>
<font size="4" color="">Click on any of the links on the
left to:</font>
</td>
</tr>
<tr>
<td align="center"><font size="" color="">Manage
Users</font></td>
</tr>
</tr>
<tr>
<td align="center"><font size="" color="">Manage
Messages</font></td>
</tr>';
echo '</center></table>';
}
Basically, an action variable is submitted from within the script by the links and will contain the values specified in the "case" conditions. The values in the links are descriptive of what functions need to be carried out. For example, listmsgs will trigger a call to the listmsgs() function. Here’s what the links section looks like in code:
<a href="<? echo $_SERVER['PHP_SELF'] ?>?action=listmsgs">List
All Messages </a>
<a href="<? echo $_SERVER['PHP_SELF'] ?>?action=listcat">List
Categories </a>
<a href="<? echo $_SERVER['PHP_SELF'] ?>?action=listusers">List
All Users </a>
<a href="../LoginScript/register.php?theadmin=1">Create New
User</a>
<a href="<? echo $_SERVER['PHP_SELF'] ?>?action=listusers">List
All Users </a>
Below is a screen shot of the main.php page:
There are a couple of other background pages that help to run the admin for the admin script, some of which I will try to explain:
- Functions.php – Contains all the functions used in admin.
- Delete.php – Used to delete articles and their comments.
- Delete_users.php – Used to delete users.
- Delete_cat.php - Used to delete categories.
- Ban.php – Used to ban users.
- New_post.php -- Used for creating new threads and posts.
Next: Functions.php >>
More MySQL Articles
More By Jacques Noah