Home arrow PHP arrow Page 2 - User Management in a PHP Invoicing System

The Action column - PHP

In this fourth and final article covering the creation of a PHP invoicing system, we're going to put together the user management section. In this section we will be able to view all available users and do all the associated things like deleting or updating user details. We are also going to be able to add new users.

  1. User Management in a PHP Invoicing System
  2. The Action column
  3. Emailing reminders
  4. User settings page
By: Leidago
Rating: starstarstarstarstar / 6
September 27, 2006

print this article



The action column in the above table has links to two pages, Delusers.php and Uprofile.php. Delusers.php removes a user from the database. Uprofile.php shows the details about a user, and doubles as an update page.

Let's look at the code that removes a user from the database:

include "config.php";
$query = "DELETE FROM users WHERE uid = '".$_GET['uid']."'";
echo mysql_error();

In this code, a user ID is received and is then used to remove the user from the users table with a "delete" query. If the query is successful the user is redirected to the allusers page.

Next we are going to deal with how to add a new user. Create a new PHP document and save it as "new_user.php." To create a new user, we will need to create a form to take input from the creator.  Since this will potentially give full access to the system to the yet-to-be-created user, we will need to make sure that only the "admin" has access to this page. Here's the HTML code for the form:

//check if level is admin. ONLY Admin can create new users
if($_SESSION['level'] == "admin"){
            <form action="uprofile.php" method="post"
            <table width="100%" border="0" cellspacing="1">
    <td colspan="2"></td>
    <td valign="top"><img src="images/icon_user.gif" width="36"
height="41" /></td>
    <td valign="top"><h1>User Information</h1></td>
    <td width="8%">&nbsp;</td>
    <td width="92%">&nbsp;</td>

    <td class="td">Username</td>
    <td><input name="uname" type="text" id="uname"
size="80" /></td>
    <td><input name="upass" type="password" id="upass" size="80"/></td>
    <td>First Name </td>
    <td><input name="fname" type="text" id="fname"
size="80"  /></td>
    <td>Last Name </td>
    <td><input name="lname" type="text" id="lname" size="80"  />
            <input name="level" type="hidden" value="normal" /></td>
    <td><input type="submit" name="submit" value="Add User" /></td>
            <? }else{?>
            <p>You are not authorized to create new

            </td></tr></table><? }?>

To make sure that an administrator has accessed the page, I have inserted the admin check code, so if a non-admin user tries to access the page they will get a "You are not authorized to create new users" message instead of the form.

To handle form information, add the following code at the top of the page:

<? include "FCKeditor/fckeditor.php";
include "config.php";
$query_ins = "INSERT INTO users SET uname='".trim(addslashes
$query_ins .= "fname = '".trim(addslashes($_POST['fname']))."',";
$query_ins .= "lname = '".trim(addslashes($_POST
['lname']))."',level = '".trim(addslashes($_POST['level']))."'";
echo mysql_error();

This code will process the form data by running an insert query as shown above. Once a record is inserted, the user will then be redirected to the allusers page where the newly created user details will be displayed.

Below is a screen shot of what the page looks like:

>>> More PHP Articles          >>> More By Leidago

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: