HomeMySQL Page 2 - Creating the Admin Script for a PHP/MySQL Blogging System
The Admin script - MySQL
In this part of the series we will be writing the administration of the blog. The idea is to give the owner of the blog the ability to manage the blog by being able to remove users and articles as required, or to alter the status of users by upgrading them to admin status or banning them. It is also a place where the administrator can start new topics that will then garner their own replies.
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.