-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.php
262 lines (214 loc) · 10.5 KB
/
update.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<?php include 'header.php' ?>
<div class="container mt-4">
<div class="col-md-9">
<?php
session_start();
require_once("db.php");
if (!empty($_POST["save"])) {
$directory = "uploads/";
unlink($directory . $row["image"]);
move_uploaded_file($_FILES["image"]["tmp_name"], "uploads/" . $_FILES["image"]["name"]);
$location1 = $_FILES["image"]["name"];
$fname = $_POST['fname'];
$mname = $_POST['mname'];
$lname = $_POST['lname'];
$gender = $_POST['gender'];
$mail = $_POST['mail'];
$mobile_no = $_POST['mobile_no'];
$date_of_birth = $_POST['date_of_birth'];
$e_status = $_POST['e_status'];
if ((!($_FILES['image']['name']))) /* If there Is No file Selected*/ {
$pdo_statement = $conn->prepare("UPDATE employee SET fname='$fname', mname='$mname', lname='$lname', gender='$gender', mail='$mail', mobile_no='$mobile_no', date_of_birth='$date_of_birth', e_status='$e_status'
WHERE eid=" . $_GET["eid"]);
$result = $pdo_statement->execute();
$states = $_POST['states'];
$country = $_POST['country'];
$id = $_GET["eid"];
foreach ($_POST['add_line1'] as $k => $val) {
$q2 = "INSERT INTO eaddress (employee_id, add_line1, states, country) VALUES ('$id', '$val', '$states', '$country')";
$conn->exec($q2);
}
if ($result) {
$_SESSION['message'] = 'Successfully Updated!!!';
header('location:index.php');
}
} else /* If file is Selected*/ {
$pdo_statement = $conn->prepare("UPDATE employee SET photograph ='$location1', fname='$fname', mname='$mname', lname='$lname', gender='$gender', mail='$mail', mobile_no='$mobile_no', date_of_birth='$date_of_birth', e_status='$e_status'
WHERE eid=" . $_GET["eid"]);
$result = $pdo_statement->execute();
$states = $_POST['states'];
$country = $_POST['country'];
$id = $_GET["eid"];
foreach ($_POST['add_line1'] as $k => $val) {
$q2 = "INSERT INTO eaddress (employee_id, add_line1, states, country) VALUES ('$id', '$val', '$states', '$country')";
$conn->exec($q2);
}
if ($result) {
$_SESSION['message'] = 'Successfully Updated!!!';
header('location:index.php');
}
}
}
$pdo_statement = $conn->prepare("SELECT * FROM employee WHERE eid=" . $_GET["eid"]);
$pdo_statement->execute();
$result = $pdo_statement->fetchAll();
$result2 = $conn->prepare("SELECT * FROM eaddress WHERE employee_id=" . $_GET["eid"]);
$result2->execute();
$results = $result2->fetchAll();
$result2->execute();
?>
<div class="card mb-5">
<div class="card-header">
<h3 class="btn btn-primary"><i class="fa fa-lg fa-edit"></i> Update Employee</h3>
</div>
<div class="card-body">
<form class="form-horizontal" method="post" action="" enctype="multipart/form-data">
<div class="form-group row mb-3">
<label class="control-label col-md-3">First Name:</label>
<div class="col-md-9">
<input type="text" name="fname" class="form-control" value="<?php echo $result[0]['fname']; ?>">
</div>
</div>
<div class="form-group row mb-3">
<label class="control-label col-md-3">Middle Name:</label>
<div class="col-md-9">
<input type="text" name="mname" class="form-control" value="<?php echo $result[0]['mname']; ?>">
</div>
</div>
<div class="form-group row mb-3">
<label class="control-label col-md-3">Last Name:</label>
<div class="col-md-9">
<input type="text" name="lname" class="form-control" value="<?php echo $result[0]['lname']; ?>">
</div>
</div>
<div class="form-group row mb-3">
<label class="control-label col-md-3">Gender:</label>
<div class="col-md-9">
<select name="gender" id="gender" class="form-control" required="true">
<option value="<?php echo $result[0]['gender']; ?>"><?php echo $result[0]['gender']; ?></option>
<option>Male</option>
<option>Female</option>
<option>Other</option>
</select>
</div>
</div>
<div class="form-group row mb-3">
<label class="control-label col-md-3">Mail:</label>
<div class="col-md-9">
<input type="text" name="mail" class="form-control" value="<?php echo $result[0]['mail']; ?>">
</div>
</div>
<div class="form-group row mb-3">
<label class="control-label col-md-3">Mobile No:</label>
<div class="col-md-9">
<input type="number" name="mobile_no" class="form-control" value="<?php echo $result[0]['mobile_no']; ?>">
</div>
</div>
<div class="form-group row mb-3">
<label class="control-label col-md-3">Date Of Birth:</label>
<div class="col-md-9">
<input type="date" name="date_of_birth" class="form-control" value="<?php echo $result[0]['date_of_birth']; ?>">
</div>
</div>
<div class="form-group row mb-3">
<label class="control-label col-md-3">Select Your Photograph:</label>
<div class="col-md-9">
<div class="form-file">
<input type="file" class="form-file-input" name="image" id="customFile">
<label class="form-file-label" for="customFile">
<span class="form-file-text">Choose file...</span>
<span class="form-file-button">Browse</span>
</label>
</div>
</div>
</div>
<div class="form-group row mb-3">
<div class="col-md-9">
<?php if ($result[0]['photograph'] != "") : ?>
<img data-aos="zoom-in" src="uploads/<?php echo $result[0]['photograph']; ?>" width="80px" height="80px">
<?php else : ?>
<img src="images/default.png" width="100px" height="100px">
<?php endif; ?>
</div>
</div>
<div class="form-group row mb-3">
<label class="control-label col-md-3">Status:</label>
<div class="col-md-9">
<select name="e_status" id="e_status" class="form-control" required="true">
<option value="<?php echo $result[0]['e_status']; ?>"><?php echo $result[0]['e_status']; ?></option>
<option>Active</option>
<option>Inactive</option>
</select>
</div>
</div>
<div class="form-group row mb-3">
<label class="control-label col-md-3">Address:</label>
<div class="col-md-6 input_fields_wrap">
<?php if (!$results) { //<-- this should be $result_table ?
echo "<p>No address found.</p>";
} else {
}
?>
<?php
for ($i = 0; $row1 = $result2->fetch(); $i++) {
$id = $row1['employee_id'];
$aid = $row1['aid'];
?>
<input id="<?php echo $aid; ?>" type="text" name="add_line1" class="form-control mt-2" value="<?php echo $row1['add_line1']; ?>" readonly="true">
<input type="checkbox" class="emp_checkbox" data-aid="<?php echo $aid; ?>">
<a href="update_addr.php?aid=<?php echo $aid; ?>" class="mt-2 btn btn-sm btn-primary"><i class="fa fa-pencil-square-o" aria-hidden="true"></i></a> |
<a class='delbtn mt-2 btn btn-sm btn-danger' data-aid=<?php echo $row1['aid']; ?> href='javascript:void(0)'><i class="fa fa-trash-o" aria-hidden="true"></i></a>
<?php } ?>
</div>
<?php if (!$results) { //<-- this should be $result_table ?
// echo "<p>No address found.</p>";
echo '<div class="col-md-3">
<button class=" btn btn-primary btn-sm add_field_button"><i class="fa fa-fw fa-lg fa-plus-circle"></i>Add More Address</button>
</div>
<div class="form-group row mb-3">
<label class="control-label col-md-3">State:</label>
<div class="col-md-9">
<input type="text" name="states" class="form-control">
</div>
</div>
<div class="form-group row mb-3">
<label class="control-label col-md-3">Country:</label>
<div class="col-md-9">
<input type="text" name="country" class="form-control">
</div>
</div>';
} else {
?>
<div class="col-md-3">
<a class='delAddrBtn mt-2 btn btn-sm btn-danger' data-aid=<?php echo $aid; ?> href='javascript:void(0)'><i class="fa fa-trash-o" aria-hidden="true"></i> Delete Selected</a>
<button class="mt-2 btn btn-primary btn-sm add_field_button"><i class="fa fa-fw fa-lg fa-plus-circle"></i>Add More Address</button>
</div>
</div>
<div class="form-group row mb-3">
<label class="control-label col-md-3">State:</label>
<div class="col-md-9">
<input type="text" name="states" class="form-control" value="<?php echo $results[0]['states']; ?>">
</div>
</div>
<div class="form-group row mb-3">
<label class="control-label col-md-3">Country:</label>
<div class="col-md-9">
<input type="text" name="country" class="form-control" value="<?php echo $results[0]['country']; ?>">
</div>
</div>
<?php
}
?>
</div>
<div class="card-footer text-muted">
<div class="row">
<div class="col-md-9 col-md-offset-3">
<input class="btn btn-primary" value="Update" type="submit" name="save"> <a class="btn btn-secondary" href="index.php">Cancel</a>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
<?php include 'footer.php' ?>