PHP
  Home arrow PHP arrow User Management in a PHP Invoicing System
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

User Management in a PHP Invoicing System
By: Leidago
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 5
    2006-09-27


    Table of Contents:
  • User Management in a PHP Invoicing System
  • The Action column
  • Emailing reminders
  • User settings page

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    User Management in a PHP Invoicing System
    ( Page 1 of 4 )

    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.
    Three downloadable files are available for this article; you can access them here, here, and here.

    Let's start by showing how we are going to list all the users in the database. Create a new PHP document and save it as allusers.php. On this page we are going to display user names and full names.

    But before we do anything else, let's create the query that will retrieve all the user details from the database. On the very top of the page add the following code:

    <?
    include "config.php";
    $query_users = "SELECT uid, uname, fname,lname  FROM users ORDER BY uid
    DESC";
    $result_users = mysql_query($query_users);
    $num_users = mysql_num_rows($result_users);
    ?>

    As a matter of good coding practice, not to mention security, I have not retrieved the password of the user at this stage. It will be retrieved only when the user wants to view his/her profile, later on.

    So let's create a table with the above headers as well as a column with "action" as its header:

    <tr class="tblheadings">
              <td><strong>User  Name</strong> </td>
                               <td><strong>Full Name </strong></td>
    <? if($_SESSION['level'] =="admin" ) {  ?>
                               <td><strong>Action</strong></td>
                               <? }?>        </tr>

    For security reasons I've added a condition on when the action column can be displayed. The column should only be shown if the person who is logged in is an administrator. This will prevent non-admin users from changing any important information. If you just want to view or change your details, then you should go to the "User settings link."

    Next we will built a dynamic table based on the results from the query:

    <?
                            if($num_users > 0){
                            while($users= mysql_fetch_assoc
    ($result_users)){
                            ?>
            <tr class="tblinfo">
              <td><?=$users['uname'];?> </td>
                            <? if($_SESSION['level'] =="admin" ) {  ?
    >
                              <td><a href="uprofile.php?uid=<?=$users
    ['uid']?>">View Full Details </a> |<a href="delusers.php?uid=<?
    =$users['uid']?>">Delete</a> <a href="uprofile.php?uid=<?=$users
    ['uid']?>">Edit</a></td>
                                <? }?>
            </tr>
                            <? } 
                            }else{?>
                            <tr>
                            <td colspan="2"><p>There are currently no
    users details available.</p></td>
                            </tr>                       

                            <? }?>

    I've put in place the same security barrier as before, so please take note.

    The above code retrieves and builds a dynamic table by checking whether the results of the query returned any rows, as in:

    if($num_users > 0){
                            while($users= mysql_fetch_assoc
    ($result_users)){
                            ?>

    If there are rows returned, a 'while()' loop is called, and the rows and cells for the retrieved data are created. In the event that there are no users, the following is displayed:

    }else{?>
                            <tr>
                            <td colspan="2"><p>There are currently no
    users details available.</p></td>
                            </tr>
                            
                           
    <? }?>

    Below is a screen shot of a users page:



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

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    Stay green...Green IT