Forum Tutorial - User Levels #1 - Setting Up & Altering Register Functions

Introduction: This tutorial will be continuing my creating a forum in PHP/MySQLi/HTML tutorial series. I have received a request to implement user levels to the system, so this tutorial will be setting up the things we need, and adjusting the register script to avoid errors. The Theory: Each user will have an access level, each of which have different permissions. There will be level 1 which will be the default of a member who is able to post threats and replies, send and receive messages, and delete their own posts. Then we will also have level 2 which will be moderators who are able to delete any post from anyone by clicking a button to the side of a post, as well as reporting members. Finally we will have level 3 admins who are able to use their own control panel to moderate the entire forum, change other users' levels as well as report and ban members! Adjusting the users table: We need to add a user/access level to the structure of the users table within our database. The default, as mentioned earlier, will be 1 which is a default member who can do the essentials on a forum... level - INT - 5 Length - 1 Default (as defined: 1). I have just added the column on the end of my table. So now in my users table I have: id, username, password, email, verified, status, signature and level. (Just thought I would mention it in-case you haven't followed my status and signature tutorial yet and receive errors once we add some code - you may need to remove some input columns when we add to the database tables). Registering Users: So now that we have altered the users table, we need to adjust our register script otherwise we may get errors due to the amount of columns being different. We need to add a new input on the end of our insertion query with the value of '1' since that is our default member level... -From-:
  1. $qq = mysqli_query($con, "INSERT INTO `users` VALUES ('', '$user', '$passMD5', '$email', '0', '', '')");
-To-:
  1. $qq = mysqli_query($con, "INSERT INTO `users` VALUES ('', '$user', '$passMD5', '$email', '0', '', '', '1')");
The next part of this tutorial will be on either adding the Moderator capabilities, or creating the admin panel. Check it out on my profile tracking page.

Add new comment