Location: PHPKode > projects > Computer Service Company Database > SOLOCMS/dogbert/searchclients.php
<? include("db.php"); // setup connection to mysql
if(isset($_GET['addheader'])) {
include ('header.php'); 
include ('navigation.php');
}
   if (empty($_POST)) {   ?>

<form name="searchclient1" method="post">
  <br><div align="center">
  First
  <input type="text" name="firstname" size="25">
  Last
  <input type="text" name="lastname" size="25">
  Phone
  <input type="text" name="phone" size="25">
  <input type="submit" value="Search For Client">
  </div>
</form>
<? }
if (!empty($_POST)) { 
 ?>
<form method="post">
 <br> <div align="center">First
    <input type="text" name="firstname" size="25">
    Last
    <input type="text" name="lastname" size="25">
    Phone
    <input type="text" name="phone" size="25">
  <input type="submit" value="Search For Client">
  </div>
</form>
<table>

<? echo "

        <p class=\"invoice\" align=\"center\">Current Clients With <b>First Name</b> Like <font color =\"red\">$firstname</font> or <b>Last Name</b> Like <font color =\"red\">$lastname</font> or <b>Phone</b> Like <font color =\"red\">$phone</font></p>

        <table align=\"center\" border=\"0\" cellpadding=\"2\" cellspacing=\"7\">
                         <tr>            <td class=\"invoice\" align=\"left\">Company</td>
            <td class=\"invoice\" align=\"left\">Last Name</td>
	     	<td class=\"invoice\" align=\"left\">First Name</td>
	     	<td class=\"invoice\" align=\"left\">Phone</td>
	     	<td class=\"invoice\" align=\"left\">Zip</td>
</tr>"; 

if ($firstname) {
$query = mysql_query("SELECT * FROM results WHERE firstname LIKE '$firstname%' LIMIT 0, 30 ");

while ($row  =  mysql_fetch_array($query))
   {
            echo "
     <tr>

            <td class=\"invoice\" align=\"left\"><a href=\"client-edit.php?edit={$row[id]}\" target=\"_parent\">{$row['company']}</a></td>
            <td class=\"invoice\" align=\"left\"><a href=\"client-edit.php?edit={$row[id]}\"  target=\"_parent\">{$row['lastname']}</a></td>
	     	<td class=\"invoice\" align=\"left\"><a href=\"client-edit.php?edit={$row[id]}\"  target=\"_parent\">{$row['firstname']}</a></td>
	     	<td class=\"invoice\" align=\"left\"><a href=\"client-edit.php?edit={$row[id]}\"  target=\"_parent\">{$row['phone']}</a></td>
	     	<td class=\"invoice\" align=\"left\"><a href=\"client-edit.php?edit={$row[id]}\"  target=\"_parent\">{$row['zip']}</a></td>
			
	</tr>" ;

   }
} 
   
   
if ($lastname) {
$query2 = mysql_query("SELECT * FROM results WHERE lastname LIKE '%$lastname%' LIMIT 0, 30 ");

   
while ($row2  =  mysql_fetch_array($query2))
   {
            echo "
     <tr>

            <td class=\"invoice\" align=\"left\"><a href=\"client-edit.php?edit={$row2[id]}\" target=\"_parent\">{$row2['company']}</a></td>
            <td class=\"invoice\" align=\"left\"><a href=\"client-edit.php?edit={$row2[id]}\"  target=\"_parent\">{$row2['lastname']}</a></td>
	     	<td class=\"invoice\" align=\"left\"><a href=\"client-edit.php?edit={$row2[id]}\"  target=\"_parent\">{$row2['firstname']}</a></td>
	     	<td class=\"invoice\" align=\"left\"><a href=\"client-edit.php?edit={$row2[id]}\"  target=\"_parent\">{$row2['phone']}</a></td>
	     	<td class=\"invoice\" align=\"left\"><a href=\"client-edit.php?edit={$row2[id]}\"  target=\"_parent\">{$row2['zip']}</a></td>
			
	</tr>" ;

  } } 
   
   
if ($phone){
	//strip to 10 digit phone numbers

$phone = preg_replace('/[^\d]/', '', $phone);
if (substr($phone, 0, 1) == '1') 
$phone = substr($phone, 1);
if (strlen($phone) == 7) $phone = $default_company_local_areacode . $phone;

$query3 = mysql_query("SELECT * FROM results WHERE phone = '$phone' OR cell = '$phone' OR fax = '$phone' LIMIT 0, 30 ");

   
   while ($row3  =  mysql_fetch_array($query3))
   {
            echo "
     <tr>

            <td class=\"invoice\" align=\"left\"><a href=\"client-edit.php?edit={$row3[id]}\" target=\"_parent\">{$row3['company']}</a></td>
            <td class=\"invoice\" align=\"left\"><a href=\"client-edit.php?edit={$row3[id]}\"  target=\"_parent\">{$row3['lastname']}</a></td>
	     	<td class=\"invoice\" align=\"left\"><a href=\"client-edit.php?edit={$row3[id]}\"  target=\"_parent\">{$row3['firstname']}</a></td>
	     	<td class=\"invoice\" align=\"left\"><a href=\"client-edit.php?edit={$row3[id]}\"  target=\"_parent\">{$row3['phone']}</a></td>
	     	<td class=\"invoice\" align=\"left\"><a href=\"client-edit.php?edit={$row3[id]}\"  target=\"_parent\">{$row3['zip']}</a></td>
			
	</tr>" ;

  } } 

 echo"<p align=\"center\"> <a href=\"client-new.php?firstname=$firstname&lastname=$lastname&phone=$phone\"  target=\"_parent\">Create New Client: $firstname - $lastname - $phone</a></p>

 ";} 
 
?>
</table>
Return current item: Computer Service Company Database