-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathedit.php
128 lines (115 loc) · 4.45 KB
/
edit.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
119
120
121
122
123
124
125
126
127
128
<?php
session_start();
if (!$_SESSION['LoggedInUser']) {
header("Location: index.php");
}
include ("includes/functions.php");
include ("includes/connection.php");
$ClientID = $_GET['ID'];
$Query = "SELECT * FROM Clients WHERE ID = '$ClientID'";
$Result = mysqli_query($Connection, $Query);
if (mysqli_num_rows($Result) > 0) {
while ($Row = mysqli_fetch_assoc($Result)) {
$ClientName = $Row['Name'];
$ClientEmail = $Row['Email'];
$ClientPhone = $Row['Phone'];
$ClientAddress = $Row['Address'];
$ClientCompany = $Row['Company'];
$ClientNotes = $Row['Notes'];
}
}
else {
$AlertMSG = "<div class='alert alert-warning'>Nothing to see here. <a href='clients.php'>Head Back</a></div> ";
}
if (isset($_POST['Update'])) {
$ClientName = ValidateFormData($_POST['ClientName']);
$ClientEmail = ValidateFormData($_POST['ClientEmail']);
$ClientPhone = ValidateFormData($_POST['ClientPhone']);
$ClientAddress = ValidateFormData($_POST['ClientAddress']);
$ClientCompany = ValidateFormData($_POST['ClientCompany']);
$ClientNotes = ValidateFormData($_POST['ClientNotes']);
$Query = "UPDATE Clients
SET Name = '$ClientName',
Email = '$ClientEmail',
Phone = '$ClientPhone',
Address = '$ClientAddress',
Company = '$ClientCompany',
Notes = '$ClientNotes' WHERE ID = '$ClientID'";
$Result = mysqli_query($Connection, $Query);
if ($Result) {
header("Location: clients.php?alert=UpdateSuccess");
}
else {
echo "Error Updating Record: " . mysqli_error($Connection);
}
}
if (isset($_POST['Delete'])) {
$AlertMSG = "<div class='alert alert-danger'>
<p>Are you sure you want to Delete this client? No take back!</p><br />
<form action ='" . htmlspecialchars($_SERVER['PHP_SELF']) . "?ID=$ClientID' method='post' >
<input type = 'submit' class='btn btn-danger btn-sm' name='confirm-delete' value='Yes, Delete!'>
<a type='button' class='btn btn-default btn-sm' data-dismiss='alert'>Oops, No Thanks!</a>
</form>
</div>";
}
if (isset($_POST['confirm-delete'])) {
$Query = "DELETE FROM Clients WHERE ID = '$ClientID'";
$Result = mysqli_query($Connection, $Query);
if ($Result) {
header("Location: clients.php?alert=Deleted");
}
else {
echo "Error Updating Record: " . mysqli_error($Connection);
}
}
mysqli_close($Connection);
include ('includes/header.php');
?>
<h1>Edit Client</h1>
<?php
echo $AlertMSG; ?>
<form action="<?php
echo htmlspecialchars($_SERVER['PHP_SELF']); ?>?ID=<?php
echo $ClientID; ?>" method="post" class="row">
<div class="form-group col-sm-6">
<label for="client-name">Name</label>
<input type="text" class="form-control input-lg" id="client-name" name="ClientName" value="<?php
echo $ClientName; ?>">
</div>
<div class="form-group col-sm-6">
<label for="client-email">Email</label>
<input type="text" class="form-control input-lg" id="client-email" name="ClientEmail" value="<?php
echo $ClientEmail; ?>">
</div>
<div class="form-group col-sm-6">
<label for="client-phone">Phone</label>
<input type="text" class="form-control input-lg" id="client-phone" name="ClientPhone" value="<?php
echo $ClientPhone; ?>">
</div>
<div class="form-group col-sm-6">
<label for="client-address">Address</label>
<input type="text" class="form-control input-lg" id="client-address" name="ClientAddress" value="<?php
echo $ClientAddress; ?>">
</div>
<div class="form-group col-sm-6">
<label for="client-company">Company</label>
<input type="text" class="form-control input-lg" id="client-company" name="ClientCompany" value="<?php
echo $ClientCompany; ?>">
</div>
<div class="form-group col-sm-6">
<label for="client-notes">Notes</label>
<textarea type="text" class="form-control input-lg" id="client-notes" name="ClientNotes"><?php
echo $ClientNotes; ?></textarea>
</div>
<div class="col-sm-12">
<hr>
<button type="submit" class="btn btn-lg btn-danger pull-left" name="Delete">Delete</button>
<div class="pull-right">
<a href="clients.php" type="button" class="btn btn-lg btn-default">Cancel</a>
<button type="submit" class="btn btn-lg btn-success" name="Update">Update</button>
</div>
</div>
</form>
<?php
include ('includes/footer.php');
?>