HomePHP Page 4 - User Management in a PHP Invoicing System
User settings page - 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.
On this page the details of the user that is currently logged on is shown. You can also update your details at the same time as viewing them. Below is a screen shot of what it looks like:
To create this page we need to make a form with four text fields and a drop-down box. Here's the HTML code for the form:
It is basically a form with an embedded table. When the form is submitted, the code below handles its data:
Code 9:
<? include "config.php"; if(isset($_POST['submit'])){ $query_updt= "UPDATE users SET uname = '".trim(addslashes($_POST ['uname']))."',upass='".trim(addslashes($_POST ['upass']))."',fname='".trim(addslashes($_POST ['fname']))."',lname='".trim(addslashes($_POST ['lname']))."',level='".trim(addslashes($_POST['level']))."'"; if(mysql_query($query_updt)){ $msg= "Your profile has been updated."; }else{ $msg="Could not update your profile because ".mysql_error(); } } if(isset($_GET['uid'])){ $query_up= "SELECT * FROM users WHERE uid = '".$_GET['uid']."'"; $up_result = mysql_query($query_up); $num = mysql_num_rows($up_result); $row_up = mysql_fetch_assoc($up_result); }else{ $query_up= "SELECT * FROM users WHERE uid = '".$_SESSION['u_id']."'"; $up_result = mysql_query($query_up); $num = mysql_num_rows($up_result); $row_up = mysql_fetch_assoc($up_result); } ?>
This code does two things. First it checks to see whether the form data is submitted and then runs an update query. Second, when this page is first opened, a query is run to retrieve the information relating to the user that is currently logged on. This is the second query in the code listing above.
Conclusion
If you are using an invoicing system that is used by many people, user management becomes very important. This is mainly because you have to be able to record and track invoice activity as a means of preventing fraud. With a more advanced user management system you will be able to tell what a particular user was doing and how many invoices he or she issued during any given period. With little changes to the code, you can achieve this.