Under the customers menu, there is a sub menu "new Customer" to create a new customer. Following fields are included in the customers database table.
- Customer_ID - The primary key is an auto increment integer value
- Customer Title - This includes (Mr / Mrs / Ms / Dr / Rev)
- Customer Name
- Customer Address - is divided in to two fields
- City
- Telephone
- Fax
- Web
- Comments
- Username
- Password
We create a username and a password for each customer to login to customer app and view construction progress.
New Customer File Source Code
<?php include("inc/page_header.php"); ?>
<?php
if(check('Add/Edit Customers') != 'Valid'){
header("Location: sys_home.php?pre=error");
ob_end_flush();
}
?>
<div class="wrapper">
<div class="s60">
<div class="boxtitle">Customer Details</div>
<?php
// form handling on submit
if(isset($_POST['submit'])){
$customer_name = $_POST['customer_name'];
$add1 = $_POST['add1'];
$add2 = $_POST['add2'];
$city = $_POST['city'];
$telephone = $_POST['telephone'];
$fax = $_POST['fax'];
$email = $_POST['email'];
$web = $_POST['web'];
$comm = $_POST['comm'];
$title = $_POST['custitle'];
$username = $_POST['username'];
$password = $_POST['password'];
if($customer_name == ''){ $error = "Please enter Customer Name!"; }
if($city == ''){ $error = "Please enter City!"; }
if($username == '' || $password = ''){ $error = "Please enter Username and Password!"; }
// duplicates
$q = mysql_query("SELECT * FROM customers WHERE Customer_Name = '$customer_name' OR Customer_Username = '$username'");
if(mysql_num_rows($q) > 0){
$error = "This customer or username is already in the system!";
}
if(!isset($error)){
mysql_query("
INSERT INTO customers
(Customer_Title, Customer_Name, Customer_Address, Customer_Address_2, Customer_City, Customer_Telephone, Customer_Fax, Customer_Email, Customer_Web, Customer_Comments, Customer_Username, Customer_Password)
VALUES ('$title', '$customer_name', '$add1', '$add2', '$city', '$telephone', '$fax', '$email', '$web', '$comm', '$username', '$password')
");
$noerror = "Customer details has been added to the database!";
}
}
// end of form handling
?>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<table>
<tr id="sh5">
<td> Title:</td>
<td><select name="custitle" size="1">
<option value="Mr." selected>Mr.</option>
<option value="Mrs.">Mrs.</option>
<option value="Ms.">Ms.</option>
<option value="Rev.">Rev.</option>
</select>
</td>
</tr>
<tr id="sh8">
<td> Site / Customer Name:</td>
<td><input type="text" size="35" name="customer_name" value="<?php if(isset($_POST['submit']) && isset($error)){ echo $customer_name; } ?>">
</td>
</tr>
<tr id="sh5">
<td> Address:</td>
<td><input type="text" size="35" name="add1" value="<?php if(isset($_POST['submit']) && isset($error)){ echo $add1; } ?>"><br />
<input type="text" size="45" name="add2" value="<?php if(isset($_POST['submit']) && isset($error)){ echo $add2; } ?>"></td>
</tr>
<tr id="sh8">
<td> City:</td>
<td><input type="text" size="25" name="city" value="<?php if(isset($_POST['submit']) && isset($error)){ echo $city; } ?>"></td>
</tr>
<tr id="sh5">
<td> Telephone:</td>
<td><input type="text" size="30" name="telephone" value="<?php if(isset($_POST['submit']) && isset($error)){ echo $telephone; } ?>">
</tr>
<tr id="sh8">
<td> Fax:</td>
<td><input type="text" size="15" name="fax" value="<?php if(isset($_POST['submit']) && isset($error)){ echo $fax; } ?>"></td>
</tr>
<tr id="sh5">
<td> Email:</td>
<td><input type="text" size="40" name="email" id="email" value="<?php if(isset($_POST['submit']) && isset($error)){ echo $email; } ?>"></td>
</tr>
<tr id="sh8">
<td> Website:</td>
<td><input type="text" size="40" name="web" value="<?php if(isset($_POST['submit']) && isset($error)){ echo $web; } ?>"></td>
</tr>
<tr id="sh8">
<td> Username:</td>
<td><input type="text" size="40" name="username" value="<?php if(isset($_POST['submit']) && isset($error)){ echo $username; } ?>"></td>
</tr>
<tr id="sh8">
<td> Password:</td>
<td><input type="text" size="40" name="password" value="<?php if(isset($_POST['submit']) && isset($error)){ echo $password; } ?>"></td>
</tr>
<tr id="sh5">
<td> Comments:</td>
<td><textarea cols="40" rows="4" name="comm"><?php if(isset($_POST['submit']) && isset($error)){ echo $comm; } ?></textarea></td>
</tr>
<tr>
<td> </td>
<td><input class="btn" type="submit" name="submit" value="Add Customer"></td>
</tr>
</table>
</form>
</div>
<div class="s40">
<p><strong>Add New Customer<br>
</strong>Use this form to add new customer to the system.</p>
<?php
if(isset($error)){
echo "<div class=\"errordiv\">{$error}</div>";
}
if(isset($noerror)){
echo "<div class=\"noerrordiv\">";
echo $noerror;
echo "</div>";
}
?>
</div>
</div>
<?php include("inc/page_footer.php"); ?>


Comments
Post a Comment