To create a new customer, we created a menu called "Customers" and linked to "customers.php" file. In the customers form, following fields are defined:
- Date - is the date of record creation
- Name - is the customer name
- NIC - is the customer's Identity card number, this is the unique number we use to cross check duplicated customers. Only one NIC number is allowed in the database (customers table).
- Telephone - This is also a mandatory field.
- Email - Optional input of customer's email address
- Sex - Male or Female
- Address - Postal address of the customer.
Except "Email" all other fields are mandatory. We check this in the PHP script after submit of the form. There is a list to view created customers grouped in to categories as follows:
- All Customers
- Black Listed Customers
- Suspended Customers
- Active Customers
We can edit customer's details and Status (Active, Black Listed, Suspended) by selecting appropriate link and view list of customers. There is a link to edit customer details.
"Customers.php" Source Code
<?php include("header.php"); ?>
<div style="width:60%; float:left; margin-right:30px;">
<h3>New Customer</h3>
<?php
if(isset($_POST['submit'])){
$cus_date = $_POST['date'];
$cus_name = $_POST['name'];
$cus_nic = $_POST['nic'];
$cus_tel = $_POST['tel'];
$cus_email = $_POST['email'];
$sex = $_POST['sex'];
$address = $_POST['address'];
if($cus_date == '' || $cus_name == '' || $cus_nic == '' || $cus_tel == '' || $address == ''){
$error = "Please enter all required fields.";
}
if(!isset($error)){
// no form errors. check for duplicates
$q = mysql_query("SELECT Cus_ID FROM customers WHERE Cus_NIC = '$cus_nic'");
if(mysql_num_rows($q) > 0){
$error = "This customer already created!";
}
}
if(!isset($error)){
mysql_query("INSERT INTO customers (Cus_Date, Cus_Name, Cus_NIC, Cus_Tel, Cus_Email, Cus_Sex, Cus_Add) VALUES ('$cus_date', '$cus_name', '$cus_nic', '$cus_tel', '$cus_email', '$sex', '$address')");
$noerror = "Customer has been added.";
}
}
// messages
if(isset($error)){
echo "<div class='error'><strong>Error:</strong> {$error}</div>";
}
if(isset($noerror)){
echo "<div class='noerror'><strong>Success:</strong> {$noerror}</div>";
}
?>
<form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<table border="0">
<tr>
<td>Date *</td>
<td><input type="text" name="date" size="15" value="<?php if(isset($cus_date)){ echo $cus_date; }else{ echo $date; } ?>" /></td>
</tr>
<tr>
<td>Name *</td>
<td><input type="text" name="name" size="50" value="<?php if(isset($cus_name)){ echo $cus_name; } ?>" /></td>
</tr>
<tr>
<td>N.I.C. *</td>
<td><input type="text" name="nic" size="20" value="<?php if(isset($cus_nic)){ echo $cus_nic; } ?>" /></td>
</tr>
<tr>
<td>Telephone *</td>
<td><input type="text" name="tel" size="20" value="<?php if(isset($cus_tel)){ echo $cus_tel; } ?>" /></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email" size="50" value="<?php if(isset($cus_email)){ echo $cus_email; } ?>" /></td>
</tr>
<tr>
<td>Sex *</td>
<td>
<input type="radio" name="sex" value="M" <?php if(isset($sex)){ if($sex == "M"){ echo "checked"; }}else{ echo "checked"; } ?> /> Male
<input type="radio" name="sex" value="F" <?php if(isset($sex) && $sex == "F"){ echo "checked"; } ?> /> Female
</td>
</tr>
<tr>
<td>Address *</td>
<td><textarea cols="40" rows="4" name="address"><?php if(isset($address)){ echo $address; } ?></textarea></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" value="Submit" /></td>
</tr>
</table>
</form>
</div>
<div style="width:36%; float:left;">
<h3>Search</h3>
<form method="post" action="search.php">
N.I.C. <input type="text" name="nic" size="20" /> <input type="submit" name="submit" value="Search" />
</form>
<h3>View Customers</h3>
<ul>
<li><a href="view_customers.php?t=all">All Customers</a></li><br />
<li><a href="view_customers.php?t=B">Black Listed Customers</a></li><br />
<li><a href="view_customers.php?t=S">Suspended Customers</a></li><br />
<li><a href="view_customers.php?t=A">Active Customers</a></li><br />
</ul>
</div>
<div style="clear:both;"></div>
<?php include("footer.php"); ?>
0 comments:
Post a Comment