HomePHP Client Management for a PHP Invoicing System
Client Management for a PHP Invoicing System
What's an invoicing system that can't manage the data for the clients you're invoicing? This article, the third of four parts, shows how to make managing your clients easy. This part of the system allows you to view a full list of client names, and add, update or remove clients from your database.
It is up to you how much information about clients you want to keep. As far as this article is concerned, I will only keep the information that is needed to run an invoice system. The obvious information to store about clients is name, address, email, phone number and of course the date that you started working with the client. You are very limited in what you can do with client information, in fact the few things you can do are add a new client, and remove, update, and view client data.
So let's create a table that will reflect this information:
CREATE TABLE `client` ( `id` int(4) unsigned zerofill NOT NULL auto_increment, `name` varchar(100) NOT NULL default '', `address` text NOT NULL, `date_added` date NOT NULL default '0000-00-00', `email` varchar(100) NOT NULL default '', `contact_name` varchar(100) NOT NULL default '', `phone_no` varchar(60) NOT NULL default '', PRIMARY KEY (`id`) ) TYPE=MyISAM AUTO_INCREMENT=12 ;
Simply copy and paste the above code into your MySQL clients' SQL window and run the SQL. Once the table has been created and it's all working, create a new PHP document and save it as "allclients.php." This page will list all the clients in the database. At the very top of the page, add the following code:
Code7 allclients.php
<? include "config.php"; $query_clients = "SELECT * FROM client ORDER BY id DESC"; $result_clients = mysql_query($query_clients); $num_clients = mysql_num_rows($result_clients); ?>
The above code simply retrieves all the client data from the database. The retrieved number of rows is stored in the "$num_clients" variable.