PHP
  Home arrow PHP arrow Page 4 - Client Management for a PHP Invoicing ...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
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

Client Management for a PHP Invoicing System
By: Leidago
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 14
    2006-09-20

    Table of Contents:
  • Client Management for a PHP Invoicing System
  • Building a table
  • Deleting clients and viewing their details
  • Updating client information
  • Adding a new client

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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


    Client Management for a PHP Invoicing System - Updating client information


    (Page 4 of 5 )

    To update client information we need to create a form that will display all of the client's current information:

    <form action="edClient.php" method="post" name="updateclient">
                <input name="cid" type="hidden" value="<?=$_GET
    ['cid'];?>" />
                <input name="dates" type="hidden" value="<?=$clients
    ['date_added'];?>" />
                <table width="100%" border="0" cellspacing="1"
    class="block">
            <tr>
              <td colspan="2"><table width="100%" height="19"
    border="0">
                <tr class="heading">
                  <td width="22%"><a href="Main.php" class="link">
    [MENU]</a></td>
                  <td width="17%"> <a href="allclients.php">CLIENT
      LISTINGS</a> </td>
                  <td width="24%">USER:<?=$user?></td>
                  <td width="37%"><a href="logout.php"
    class="link">LOGOUT</a></td>
                </tr>
              </table></td>
              </tr>                         

            <tr>
              <td width="13%">Client Name </td>
              <td width="87%"><input name="cname" type="text"
    id="cname" size="60"  value="<?=$clients['name'];?>"/></td>
            </tr>
            <tr>
              <td>Address</td>
              <td>
                               <?php
    $oFCKeditor = new FCKeditor('address') ;
    $oFCKeditor->BasePath = 'FCKeditor/';
    $oFCKeditor->Value = $clients['address'];
    $oFCKeditor->Create() ;
    ?>
                              </td>
            </tr>
            <tr>
              <td>Contact Name </td>
              <td><input name="contact" type="text" id="contact"
    size="60"  value="<?=$clients['contact_name'];?>"/></td>
            </tr>
                            <tr>
              <td>Telephone Number </td>
              <td><input name="phone" type="text" id="phone"
    size="60"  value="<?=$clients['phone_no'];?>"/></td>
            </tr>
                            <tr>
              <td>Email Address </td>
              <td><input name="email" type="text" id="email"
    size="60"  value="<?=$clients['email'];?>"/></td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td><input type="submit" name="submit" value="Update
    Client" /></td>
            </tr>                       

          </table>

    As you can see from the code, the form itself is contained within a table and has several form elements in which the retrieved query results are placed. The code below shows how the records were retrieved:

    <?
    ob_start();
    include "config.php";
    include "FCKeditor/fckeditor.php";

    A

    if(isset($_GET['cid'])){
    $query_clients = "SELECT * FROM client WHERE id = '".$_GET
    ['cid']."'";
    $result_clients = mysql_query($query_clients);
    $num_clients = mysql_num_rows($result_clients);
    $clients = mysql_fetch_assoc($result_clients);
    }

    B

    if(isset($_POST['submit'])){

    $query_ins = "UPDATE client SET name='".trim(addslashes($_POST
    ['cname']))."',address='".trim(addslashes($_POST
    ['address']))."',";
    $query_ins .= "date_added = '".trim(addslashes($_POST
    ['dates']))."',email = '".trim(addslashes($_POST['email']))."',";
    $query_ins .= "contact_name = '".trim(addslashes($_POST
    ['contact_name']))."',phone_no = '".trim(addslashes($_POST
    ['phone_no']))."' WHERE id = '".$_POST['cid']."'";
    if(mysql_query($query_ins)){
    header("location:allclients.php");
    }else{
    echo mysql_error();
    }

    }
    ?>

    The code has two parts. First it retrieves client information based on the client id that is sent from the allclients page:

    if(isset($_GET['cid'])){
    $query_clients = "SELECT * FROM client WHERE id = '".$_GET
    ['cid']."'";
    $result_clients = mysql_query($query_clients);
    $num_clients = mysql_num_rows($result_clients);
    $clients = mysql_fetch_assoc($result_clients);
    }

    Then it updates the record when the form is submitted:

    $query_ins = "UPDATE client SET name='".trim(addslashes($_POST
    ['cname']))."',address='".trim(addslashes($_POST
    ['address']))."',";
    $query_ins .= "date_added = '".trim(addslashes($_POST
    ['dates']))."',email = '".trim(addslashes($_POST['email']))."',";
    $query_ins .= "contact_name = '".trim(addslashes($_POST
    ['contact_name']))."',phone_no = '".trim(addslashes($_POST
    ['phone_no']))."' WHERE id = '".$_POST['cid']."'";
    if(mysql_query($query_ins)){
    header("location:allclients.php");
    }else{
    echo mysql_error();
    }

    Once the update has been completed, the user is sent back to the allclients page. Below is a screen shot of the allclients page:

    More PHP Articles
    More By Leidago


       · A couple of things:- shorttags will not work on all servers. It's always better to...
       · What tags are you referring to? And also where exactly is escaping not...
       · With shorttags I mean <? instead of the full tags <?php (hope that comes through the...
       · Thanks will keep this in mind.
     

       

    PHP ARTICLES

    - Authentication Scripts for a User Management...
    - Utilizing the Use Keyword for Namespaces in ...
    - Building a User Management Application
    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
    Stay green...Green IT