-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit_customer_result.php
118 lines (118 loc) · 2.96 KB
/
edit_customer_result.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<? require_once("connect_to_DB.php"); // inserts contents of this file here ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>New Customer Processed</title>
<link rel="stylesheet" href="hw2.css"/>
<?session_start();
connectDB();?>
</head>
<body>
<h1><a href="http://tinyurl.com/mstgdqk"><img src="http://tinyurl.com/on58dwh" alt=" photo Untitled_zps8bfcff57.jpg"/></a></h1>
<?
include ('navbar_func.php');
echo navbar();
?>
<?
$customer = $_POST['custID'];
$region = $_POST['region'];
$company = $_POST['companyname'];
$lname = $_POST['lastname'];
$fname = $_POST['firstname'];
$add1 = $_POST['address1'];
$add2 =$_POST['address2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$fax = $_POST['fax'];
$email = $_POST['email'];
if($email ===""){
$email = "email@email";
}
if($fax ===""){
$fax = "000-000-0000";
}
?>
<table>
<tr>
<td>Customer ID: </td>
<td><?print $customer?></td>
<td>Region: </td>
<td><?print $region?></td>
</tr>
<tr>
<td> Company Name: </td>
<td><?print $company?></td>
</tr>
<tr>
<td> Contact Information:</td>
</tr>
<tr>
<td> Last Name: </td>
<td><?print $lname?></td>
</tr>
<tr>
<td> First Name: </td>
<td><?print $fname?></td>
</tr>
<tr>
<td> Street Address 1: </td>
<td><?print $add1?></td>
</tr>
<tr>
<td> Street Address 2: </td>
<td><?print $add2?></td>
</tr>
<tr>
<td> City: </td>
<td><?print $city?></td>
<td> State: </td>
<td><?print $state?></td>
<td> Zip: </td>
<td><?print $zip?></td>
</tr>
<tr>
<td> Phone: </td>
<td><?print $phone?></td>
<td> Fax: </td>
<td><?print $fax?></td>
<td> Email: </td>
<td><?print $email?></td>
</tr>
</table>
<?
try{
$check = "SELECT cust_id FROM customer WHERE cust_id=$customer";
$cresult = mysqli_query($db, $check);
if(!$cresult)
{
throw new Exception("Could not connect to database");
}
} catch (Exception $e){
// redirect to a custom error page (PHP or ASP.NET or …)
header("Location: error.php?msg=" . $e->getMessage() . "&line=" . $e->getLine());
}
if(mysqli_num_rows($cresult)===1){
$sql = "UPDATE customer SET cust_company='".$company."' , cust_lname='".$lname."', cust_fname='".$fname."', cust_address='".$add1."', cust_city='".$city."', cust_state='".$state."', cust_zip='".$zip."'
, region_id='".$region."', cust_phone='".$phone."', cust_fax='".$fax."', cust_email='".$email."' WHERE cust_id='".$customer."'";
if (mysqli_query($db, $sql))
{
echo "Customer Edited successfully<br/>";
}
else
{
echo "Error: " . $sql . "<br>" . mysqli_error($db);
}
}else{
echo "Customer doesn't exist <br/>";
}
?>
<form method="post" action="hw2.php">
<input type="hidden" name="page" value="home"/>
</br>
<input type="submit" value="Return"/>
</form>
</body>
</html>