-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit_customer.php
More file actions
60 lines (53 loc) · 1.93 KB
/
edit_customer.php
File metadata and controls
60 lines (53 loc) · 1.93 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
<?php
session_start();
require_once 'config/config.php';
require_once BASE_PATH.'/includes/auth_validate.php';
// Sanitize if you want
$customer_id = filter_input(INPUT_GET, 'customer_id', FILTER_VALIDATE_INT);
$operation = filter_input(INPUT_GET, 'operation', FILTER_SANITIZE_STRING);
($operation == 'edit') ? $edit = true : $edit = false;
$db = getDbInstance();
// Handle update request. As the form's action attribute is set to the same script, but 'POST' method,
if ($_SERVER['REQUEST_METHOD'] === 'POST')
{
// Get customer id form query string parameter.
$customer_id = filter_input(INPUT_GET, 'customer_id', FILTER_SANITIZE_STRING);
// Get input data
$data_to_db = filter_input_array(INPUT_POST);
// Insert user and timestamp
$data_to_db['updated_by'] = $_SESSION['user_id'];
$data_to_db['updated_at'] = date('Y-m-d H:i:s');
$db = getDbInstance();
$db->where('id', $customer_id);
$stat = $db->update('customers', $data_to_db);
if ($stat)
{
$_SESSION['success'] = 'Customer updated successfully!';
// Redirect to the listing page
header('Location: customers.php');
// Important! Don't execute the rest put the exit/die.
exit();
}
}
// If edit variable is set, we are performing the update operation.
if ($edit)
{
$db->where('id', $customer_id);
// Get data to pre-populate the form.
$customer = $db->getOne('customers');
}
?>
<?php include BASE_PATH.'/includes/header.php'; ?>
<div id="page-wrapper">
<div class="row">
<div class="col-lg-12">
<h2 class="page-header">Update Customer</h2>
</div>
</div>
<!-- Flash messages -->
<?php include BASE_PATH.'/includes/flash_messages.php'; ?>
<form class="form" action="" method="post" id="customer_form" enctype="multipart/form-data">
<?php include BASE_PATH.'/forms/customer_form.php'; ?>
</form>
</div>
<?php include BASE_PATH.'/includes/footer.php'; ?>