Location: PHPKode > scripts > PHP Online Invoice System > php-online-invoice-system/editclient.php
<?
/*
 * Exemplar Web hosting
 * http://www.exemplar.biz
 *
 * Title: PHP Online Invoice System
 * Version: 2.0
 * Author: Exemplar
 * Date: 01-01-2006
 *
*/

include('header.php');

  if ($id) {
echo "<h1>Edit client # $id</h1>";
}
else
{
echo " <h1>Add new client</h1>";
}


if($submit)
{
//-------------------check user name-----------------------------------------------------
$name = $_POST['name'];

$select = "select name from clients where name = '".$name."';";
$query = mysql_query($select) or die ("Mysql error! It was: ".mysql_error());
$rows = mysql_num_rows($query);
if ($rows != 0)
{

  echo ("<script language=javascript>alert ('Sorry! $name is already taken!')</script>");
  echo ("<script language=javascript>document.location.href = 'editclient.php'</script>");

exit;
}
if($name == "admin"){
  echo ("<script language=javascript>alert ('Sorry! $name is not a good thing to do!')</script>");
  echo ("<script language=javascript>document.location.href = 'editclient.php'</script>");
exit;

}
//-----------------------------------end check-------------------------------------------
$sql = "INSERT INTO clients (name,first_name,last_name, password,comments, email, company,taxid, address, city, state, zip,
night_phone_a,night_phone_b,night_phone_c,fax_phone_a,fax_phone_b,fax_phone_c, shiptoname,shiptoaddr,shiptocity,shiptostate,shiptozip)
VALUES ('$name','$first_name','$last_name','$passwd','$comments','$clientemail','$company','$taxid','$clientaddress','$clientcity',
'$clientstate','$clientzip','$night_phone_a','$night_phone_b','$night_phone_c','$fax_phone_a','$fax_phone_b','$fax_phone_c','$shiptoname','$shiptoaddr','$shiptocity',
'$shiptostate','$shiptozip')";
$result = mysql_query($sql);
echo ("<script language=javascript>document.location.href = 'editclient.php?id=$id&message=Client $id has been Created!'</script>");

}
else if($update)
{

$sql = "UPDATE clients SET name='$name',first_name='$first_name',last_name='$last_name',password='$passwd',comments='$comments',
email='$email',company='$company',taxid='$taxid',night_phone_a='$night_phone_a',night_phone_b='$night_phone_b',
night_phone_c='$night_phone_c',fax_phone_a='$fax_phone_a',fax_phone_b='$fax_phone_b',
fax_phone_c='$fax_phone_c',address='$address',city='$city',state='$state',zip='$zip',shiptoname='$shiptoname',
shiptoaddr='$shiptoaddr',shiptocity='$shiptocity',shiptostate='$shiptostate',shiptozip='$shiptozip'
WHERE clientid=$id";
$result = mysql_query($sql);
echo ("<script language=javascript>document.location.href = 'editclient.php?id=$id&message=Client $id has been Updated!'</script>");



}
else if($id)
{
$result = mysql_query("SELECT * FROM clients WHERE clientid=$id",$db);
$row = mysql_fetch_array($result);

?>
</p>
<br><font color=red size=4><?php if (isset($_GET['message'])) { echo ' - '.$_GET['message']; } ?></font><BR>
<?

//-------------NEXT PREVIOUS----------------------------------------------------------------------

$sql ="SELECT * FROM clients WHERE clientid < '$id' ORDER by clientid DESC LIMIT 1";

$resultp = mysql_query($sql);
$previousrows = mysql_num_rows($resultp);
while ($prerow = mysql_fetch_array($resultp)) {
$prev=$prerow['clientid'];
}
//echo $prev;

$sql2 ="SELECT clientid FROM clients WHERE clientid > '$id' ORDER by clientid ASC LIMIT 1";

$resultn = mysql_query($sql2);
$nextrows = mysql_num_rows($resultn);
while ($nextrow = mysql_fetch_array($resultn)) {
$next=$nextrow['clientid'];
}
//echo $next;
if ($previousrows == "") {
echo "";
}else{
echo "<B><a href=$PHP_SELF?id=$prev>$prev <- Prev</a> | ";
}
echo "<font size=6><B>$id</B></font>";
if ($nextrows == "") {
echo "";
}else{
echo "<b> | <a href=$PHP_SELF?id=$next > Next -> $next</a></b>";
}
//-----------------end next prev-----------------------------------------------------
?><br><br>
<form name="form2a" method="post" action="<?php echo $PHP_SELF?>">
   <table width="760" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td class=topHeadrow1 valign="middle" width="50%" colspan="2">
Login Information:</td>
      <td class=topHeadrow1 valign="middle" width="10" rowspan="20">
&nbsp;</td>
      <td class=topHeadrow1 valign="middle" width="50%">
Payment History:</td>
    </tr>
    <tr>
      <td valign="top" align="right">
<input type="hidden" name="id" value="<?php echo $row["clientid"]?>">
Username:<br>
</td>
      <td valign="top" align="left">
&nbsp;<input type="text" size="20" name="name" value="<?php echo $row["name"]?>" ></td>
      <td valign="top" width="10%" rowspan="13">
<?
include('editclient_include_inv.php');
?>

      </td>
   </tr>
    <tr>
      <td valign="top" align="right">
User Password:
</td>
      <td valign="top" align="left">
&nbsp;<input type="text" name="passwd" size="20" value="<?php echo $row["password"]?>"></td>
   </tr>
    <tr>
      <td valign="top" align="right">
Comments:</td>
     <td valign="top" align="left">
<textarea cols="30" rows="5" name="comments"><? echo $row["comments"]?></textarea></td></tr>
    <tr>
      <td class=topHeadrow1 valign="middle" width="50%" colspan="2">
Contact Information:</td>
      </tr>
    <tr>
      <td valign="top" align="right" nowrap>
Company:
     </td>
      <td valign="top" align="left">
<input type="text" name="company" value="<?php echo $row["company"]?>" size="20"></td>
      </tr>
    <tr>
      <td valign="top" align="right" nowrap>
Tax ID:
     </td>
      <td valign="top" align="left">
<input type="text" name="taxid" value="<?php echo $row["taxid"]?>" size="20"></td>
      </tr>
    <tr>
      <td valign="top" align="right" nowrap>
Phone:</td>
      <td valign="top" align="left">
<input type="text" name="night_phone_a" value="<?php echo $row["night_phone_a"]?>" size="3" MAXLENGTH="3" OnKeyUp="javascript: if(this.value.length==3){document.form2a.night_phone_b.focus()}">
<input type="text" name="night_phone_b" value="<?php echo $row["night_phone_b"]?>" size="3" MAXLENGTH="3" OnKeyUp="javascript: if(this.value.length==3){document.form2a.night_phone_c.focus()}">
<input type="text" name="night_phone_c" value="<?php echo $row["night_phone_c"]?>" size="4" MAXLENGTH="4" OnKeyUp="javascript: if(this.value.length==4){document.form2a.fax_phone_a.focus()}"></td>
      </tr>
    <tr>
      <td valign="top" align="right" nowrap>
Fax:</td>
      <td valign="top" align="left">
<input type="text" name="fax_phone_a" value="<?php echo $row["fax_phone_a"]?>" size="3" MAXLENGTH="3" OnKeyUp="javascript: if(this.value.length==3){document.form2a.fax_phone_b.focus()}">
<input type="text" name="fax_phone_b" value="<?php echo $row["fax_phone_b"]?>" size="3" MAXLENGTH="3" OnKeyUp="javascript: if(this.value.length==3){document.form2a.fax_phone_c.focus()}">
<input type="text" name="fax_phone_c" value="<?php echo $row["fax_phone_c"]?>" size="4" MAXLENGTH="4" OnKeyUp="javascript: if(this.value.length==4){document.form2a.first_name.focus()}"></td>
      </tr>
    <tr>
      <td valign="top" align="right" nowrap>
Contact First name:</td>
      <td valign="top" align="left">
<input type="text" size="20" name="first_name" value="<?php echo $row["first_name"]?>" ></td>
      </tr>
    <tr>
      <td valign="top" align="right" nowrap>
Contact Last name:</td>
      <td valign="top" align="left">
<input type="text" size="20" name="last_name" value="<?php echo $row["last_name"]?>" ></td>
      </tr>
    <tr>
      <td valign="top" align="right" nowrap>
Address:</td>
      <td valign="top" align="left">
<input type="text" name="address" value="<?php echo $row["address"]?>" size="31"></td>
      </tr>
    <tr>
      <td valign="top" align="right" nowrap>
City:</td>
      <td valign="top" align="left">
<input type="text" name="city" value="<?php echo $row["city"]?>" size="20"></td>
      </tr>
    <tr>
      <td valign="top" align="right" nowrap>
State:</td>
      <td valign="top" align="left">
<input type="text" name="state" value="<?php echo $row["state"]?>" size="20"></td>
      </tr>
    <tr>
      <td valign="top" align="right" nowrap>
Zip: </td>
      <td valign="top" align="left">
<input type="text" name="zip" value="<?php echo $row["zip"]?>" size="20"></td>
      </tr>
    <tr>
      <td valign="top" align="right" nowrap>
Email:</td>
      <td valign="top" align="left">
<input type="text" name="email" value="<?php echo $row["email"]?>" size="31"></td>
      </tr>
    <tr>
      <td class=topHeadrow1 valign="middle" width="50%" colspan="2">
Shipping Information:</td>
      <td class=topHeadrow1 valign="middle" width="50%">
Invoices:</td>
    </tr>
    <tr>
      <td valign="top" nowrap align="right">

Ship to Name:

</td>
      <td valign="top" align="left">

<input type="text" name="shiptoname" value="<?php echo $row["shiptoname"]?>" size="20"></td>
      <td valign="top" width="10%" rowspan="5">

<?
include('editclient_include.php');
?>
</td>
    </tr>

    <tr>
      <td valign="top" nowrap align="right">

Address:</td>
      <td valign="top" align="left">

<input type="text" size="31" name="shiptoaddr" value="<?php echo $row["shiptoaddr"]?>"></td>
    </tr>

    <tr>
      <td valign="top" nowrap align="right">

City:</td>
      <td valign="top" align="left">

<input type="text" name="shiptocity" size="20" value="<?php echo $row["shiptocity"]?>"></td>
    </tr>

    <tr>
      <td valign="top" nowrap align="right">

State:</td>
      <td valign="top" align="left">

<input type="text" name="shiptostate" size="20" value="<?php echo $row["shiptostate"]?>"></td>
    </tr>

    <tr>
      <td valign="top" nowrap align="right">

Zip:</td>
      <td valign="top" align="left">

<input type="text" name="shiptozip" size="20" value="<?php echo $row["shiptozip"]?>"><br>
&nbsp;</td>
    </tr>

    <tr>
      <td class=topHeadrow1 valign="middle" width="100%" colspan="4">
<p align="center"><input class="form-button" type="Submit" name="update" value="Update Information"></td>
    </tr>
    <tr>
      <td valign="top" width="100%" colspan="4">
<br>
</td>
    </tr>
  </table>


  </form>

<?
}
else
{
//----------------------------begin add client--------------------------------------------------------
?>
<br><font color=red size=4><?php if (isset($_GET['message'])) { echo ' - '.$_GET['message']; } ?></font><BR>

<form name="form2b" method="post" action="editclient.php" onSubmit="return checkPw(this)">
  <table width="760" border="0">
    <tr>
      <td class="topHeadrow5" valign="top" width="100%" colspan="2">
<b><font size="4">Login Information:</font></b></td>
    </tr>
    <tr>
      <td valign="top" align="right">
Client's Username:</td>
      <td valign="top" align="left">
<input
 type="text" size="20" name="name" ></td></tr>
    <tr>
      <td valign="top" align="right">
Password:</td>
      <td valign="top" align="left">
<input type="password" name="passwd" size="20"></td></tr>
    <tr>
      <td valign="top" align="right">
Retype Password:</td>
      <td valign="top" align="left">
<input type="password" name="passwd2" size="20"></td></tr>
    <tr>
    <tr>
      <td valign="top" align="right">
Comments:</td>
     <td valign="top" align="left">
<textarea cols="30" rows="5" name="comments"></textarea></td></tr>
<td class="topHeadrow5" valign="top" width="100%" colspan="2">
<b><font size="4">Contact Information:</font></b></td>
    </tr>
        <tr>
      <td valign="top" align="right">
Company:
</td>
      <td valign="top" align="left">
<input
 type="text" name="company" size="20"></td>
    </tr>
        <tr>
      <td valign="top" align="right">
Tax ID:
</td>
      <td valign="top" align="left">
<input
 type="text" name="taxid" size="20"></td>
    </tr>
        <tr>
      <td valign="top" align="right">
Phone:</td>
      <td valign="top" align="left">
<input
 type="text" name="night_phone_a" size="3" MAXLENGTH="3" OnKeyUp="javascript: if(this.value.length==3){document.form2b.night_phone_b.focus()}">
<input
 type="text" name="night_phone_b" size="3" MAXLENGTH="3" OnKeyUp="javascript: if(this.value.length==3){document.form2b.night_phone_c.focus()}">
<input
 type="text" name="night_phone_c" size="4" MAXLENGTH="4" OnKeyUp="javascript: if(this.value.length==4){document.form2b.fax_phone_a.focus()}">
</td>
    </tr>

        <tr>
      <td valign="top" align="right">
Fax:</td>
      <td valign="top" align="left">
<input
 type="text" name="fax_phone_a" size="3" MAXLENGTH="3" OnKeyUp="javascript: if(this.value.length==3){document.form2b.fax_phone_b.focus()}">
<input
 type="text" name="fax_phone_b" size="3" MAXLENGTH="3" OnKeyUp="javascript: if(this.value.length==3){document.form2b.fax_phone_c.focus()}">
<input
 type="text" name="fax_phone_c" size="4" MAXLENGTH="4" OnKeyUp="javascript: if(this.value.length==4){document.form2b.first_name.focus()}">
</td>
    </tr>

        <tr>
      <td valign="top" align="right">
Contact First name:</td>
      <td valign="top" align="left">

<input
 type="text" size="20" name="first_name" ></td>
    </tr>

        <tr>
      <td valign="top" align="right">
Contact Last name:</td>
      <td valign="top" align="left">
<input
 type="text" size="20" name="last_name" ></td>
    </tr>

        <tr>
      <td valign="top" align="right">
Address:</td>
      <td valign="top" align="left">
<input
 type="text" size="50" name="clientaddress" ></td>
    </tr>

        <tr>
      <td valign="top" align="right">
City:</td>
      <td valign="top" align="left">
<input
 type="text" name="clientcity" size="20"></td>
    </tr>

        <tr>
      <td valign="top" align="right">
State:</td>
      <td valign="top" align="left">
<input
 type="text" name="clientstate" size="20"></td>
    </tr>

        <tr>
      <td valign="top" align="right">
Zip:</td>
      <td valign="top" align="left">
<input
 type="text" name="clientzip" size="20"></td>
    </tr>

        <tr>
      <td valign="top" align="right">
Email:</td>
      <td valign="top" align="left">
<input
 type="text" name="clientemail" size="50"></td>
    </tr>

    <tr>
      <td class="topHeadrow5" valign="top" width="100%" colspan="2">
<b><font size="4">Ship to Information:</font></b></td>
    </tr>
    <tr>
      <td valign="top" align="right">
Ship to Name:

</td>
      <td valign="top" align="left">
<input
 type="text" name="shiptoname" size="20"></td>
    </tr>
    <tr>
      <td valign="top" align="right">

Address:</td>
      <td valign="top" align="left">
<input
 type="text" size="50" name="shiptoaddr" ></td>
    </tr>
    <tr>
      <td valign="top" align="right">
City:</td>
      <td valign="top" align="left">
<input
 type="text" name="shiptocity" size="20"></td>
    </tr>
    <tr>
      <td valign="top" align="right">
State:</td>
      <td valign="top" align="left">
<input
 type="text" name="shiptostate" size="20"></td>
    </tr>
    <tr>
      <td valign="top" align="right">
Zip:</td>
      <td valign="top" align="left">
<input
 type="text" name="shiptozip" size="20"></td>
    </tr>
  </table>
  <table width="760" border="0">
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td width="10%">&nbsp;</td>
      <td width="90%"><input class="form-button" type="Submit" name="submit" value="Enter information"></td>
    </tr>
  </table>
  </form>
<p>&nbsp;</p>

<?
}
include "footer.php";
?>
Return current item: PHP Online Invoice System