-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomer_edit.php
More file actions
151 lines (133 loc) · 6.23 KB
/
Copy pathcustomer_edit.php
File metadata and controls
151 lines (133 loc) · 6.23 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
require_once 'includes/config.php';
require_once 'includes/functions.php';
require_login();
// Check if ID is provided
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
$_SESSION['error'] = 'Invalid customer ID';
header('Location: customers.php');
exit();
}
$customer_id = $_GET['id'];
try {
$pdo = new PDO(
"mysql:host=" . DB_HOST . ";dbname=" . DB_NAME,
DB_USER,
DB_PASS
);
// Handle form submission
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$sql = "UPDATE customers SET
company_name = :company_name,
contact_name = :contact_name,
email = :email,
phone = :phone,
address = :address,
city = :city,
postcode = :postcode,
notes = :notes
WHERE id = :id";
$stmt = $pdo->prepare($sql);
$stmt->execute([
'company_name' => $_POST['company_name'],
'contact_name' => $_POST['contact_name'],
'email' => $_POST['email'],
'phone' => $_POST['phone'],
'address' => $_POST['address'],
'city' => $_POST['city'],
'postcode' => $_POST['postcode'],
'notes' => $_POST['notes'],
'id' => $customer_id
]);
$_SESSION['message'] = 'Customer updated successfully';
header('Location: customers.php');
exit();
}
// Get existing customer data
$stmt = $pdo->prepare("SELECT * FROM customers WHERE id = ?");
$stmt->execute([$customer_id]);
$customer = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$customer) {
throw new Exception('Customer not found');
}
} catch (Exception $e) {
$_SESSION['error'] = 'Error: ' . $e->getMessage();
header('Location: customers.php');
exit();
}
$page_title = 'Edit Customer';
require_once 'includes/header.php';
require_once 'includes/menu.php';
?>
<div class="container py-4">
<div class="row">
<div class="col-md-8 offset-md-2">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1>Edit Customer</h1>
<div>
<a href="customer_view.php?id=<?php echo $customer_id; ?>"
class="btn btn-outline-primary me-2">View Details</a>
<a href="invoice_create.php?customer_id=<?php echo $customer_id; ?>"
class="btn btn-success">New Invoice</a>
</div>
</div>
<div class="card">
<div class="card-body">
<form method="post" action="">
<div class="row mb-3">
<div class="col-md-6">
<label for="company_name" class="form-label">Company Name</label>
<input type="text" class="form-control" id="company_name" name="company_name"
value="<?php echo htmlspecialchars($customer['company_name']); ?>" required>
</div>
<div class="col-md-6">
<label for="contact_name" class="form-label">Contact Name</label>
<input type="text" class="form-control" id="contact_name" name="contact_name"
value="<?php echo htmlspecialchars($customer['contact_name']); ?>">
</div>
</div>
<div class="row mb-3">
<div class="col-md-6">
<label for="email" class="form-label">Email</label>
<input type="email" class="form-control" id="email" name="email"
value="<?php echo htmlspecialchars($customer['email']); ?>">
</div>
<div class="col-md-6">
<label for="phone" class="form-label">Phone</label>
<input type="text" class="form-control" id="phone" name="phone"
value="<?php echo htmlspecialchars($customer['phone']); ?>">
</div>
</div>
<div class="mb-3">
<label for="address" class="form-label">Address</label>
<textarea class="form-control" id="address" name="address"
rows="2"><?php echo htmlspecialchars($customer['address']); ?></textarea>
</div>
<div class="row mb-3">
<div class="col-md-6">
<label for="city" class="form-label">City</label>
<input type="text" class="form-control" id="city" name="city"
value="<?php echo htmlspecialchars($customer['city']); ?>">
</div>
<div class="col-md-6">
<label for="postcode" class="form-label">Postcode</label>
<input type="text" class="form-control" id="postcode" name="postcode"
value="<?php echo htmlspecialchars($customer['postcode']); ?>">
</div>
</div>
<div class="mb-3">
<label for="notes" class="form-label">Notes</label>
<textarea class="form-control" id="notes" name="notes"
rows="3"><?php echo htmlspecialchars($customer['notes']); ?></textarea>
</div>
<div class="d-grid gap-2 d-md-flex justify-content-md-end">
<a href="customers.php" class="btn btn-outline-secondary me-2">Cancel</a>
<button type="submit" class="btn btn-primary">Update Customer</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<?php require_once 'includes/footer.php'; ?>