-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit.php
233 lines (144 loc) · 6.5 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
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
<?php include_once "app/autoload.php"; ?>
<?php
/**
* Edit page form isseting
*/
if (isset($_POST['add'])) {
$edit_id = $_GET['edit_id'];
// Get value
$name = $_POST['name'];
$email = $_POST['email'];
$cell = $_POST['cell'];
$uname = $_POST['uname'];
$age = $_POST['age'];
// Gernder isseting
if (isset($_POST['gender'])) {
$gender = $_POST['gender'];
}
$shift = $_POST['shift'];
$location = $_POST['location'];
/**
* Edit page Form validation
*/
if ( empty($name) || empty($email) || empty($cell) || empty($uname) || empty($age) || empty($gender) || empty($shift) || empty($location) ) {
$mess = validationMsg('All feilds are required !');
}elseif( !filter_var($email, FILTER_VALIDATE_EMAIL)){
$mess = validationMsg('Invalid Email !');
}elseif( $age <= 5 || $age >= 12 ){
// Nasted if else
if ( $age <= 5 ) {
$mess = validationMsg('Your age is under the limit !');
}elseif( $age >= 12 ){
$mess = validationMsg('Your age is over the limit !');
}
}else{
// Image uploading system
$photo_name = "";
if ( empty($_FILES['new_photo']['name'])) {
$photo_name = $_POST['old_photo'];
}else{
// File Management ( Photo updating system )
$file_name = $_FILES['new_photo']['name'];
$file_tmp_name = $_FILES['new_photo']['tmp_name'];
$file_size = $_FILES['new_photo']['size'];
$photo_name = md5( time() . rand() ) . $file_name;
move_uploaded_file($file_tmp_name, 'photo/students/' . $photo_name);
}
// Sending data to Database
$sql = "UPDATE studentsTwo SET name='$name', email='$email', cell='$cell', uname='$uname', age='$age', gender='$gender', shift='$shift', location='$location', photo='$photo_name' WHERE id='$edit_id'";
$connection -> query($sql);
$mess = validationMsg('Registration Updated !', 'success');
}
}
?>
<?php
if (isset($_GET['edit_id'])) {
$edit_id = $_GET['edit_id'];
$sql = " SELECT * FROM studentsTwo WHERE id='$edit_id' ";
$data = $connection -> query($sql);
$single_data = $data -> fetch_assoc();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="assets/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/css/style.css">
<title>Class 14</title>
</head>
<body>
<div class="student_form">
<a href="students.php" class="btn btn-primary rounded-0">Back</a>
<form class="form p-5 text-white shadow-lg" method="POST" enctype="multipart/form-data">
<h1 class="text-center">Update Student Data </h1>
<?php
if (isset($mess)) {
echo $mess;
}
?>
<div class="form-group">
<label for="exampleInputEmail1">Name</label>
<input name="name" type="text" value="<?php echo $single_data['name']; ?>" class="form-control text-white h-25">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Email</label>
<input name="email" type="text" value="<?php echo $single_data['email']; ?>" class="form-control text-white h-25">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Cell</label>
<input name="cell" type="text" value="<?php echo $single_data['cell']; ?>" class="form-control text-white h-25">
</div>
<div class="form-group">
<label for="exampleInputEmail1">User Name</label>
<input name="uname" type="text" value="<?php echo $single_data['uname']; ?>" class="form-control text-white h-25">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Age</label>
<input name="age" type="text" value="<?php echo $single_data['age']; ?>" class="form-control text-white h-25">
</div>
<div class="form-group ">
<label for="exampleInputEmail1">Gender</label><br>
<input name="gender" <?php if( $single_data['gender'] == 'Male'){ echo "checked"; } ?> type="radio" value="Male" class="text-white p-2" id="male"><label class="p-1" for="male"> Male</label>
<input name="gender" <?php if( $single_data['gender'] == 'Female'){ echo "checked"; } ?> type="radio" value="Female" class="text-white" id="female"><label class="p-1" for="female"> Female</label>
</div>
<div class="form-group ">
<label for="exampleInputEmail1">Shift</label>
<select class="form-control h-25 text-white" name="shift">
<option class="text-dark" value="">--Select--</option>
<option class="text-dark" <?php if( $single_data['shift'] == 'Day'){ echo "selected"; } ?> value="Day">Day</option>
<option class="text-dark" <?php if( $single_data['shift'] == 'Evening'){ echo "selected"; } ?> value="Evening">Evening</option>
</select>
</div>
<div class="form-group ">
<label for="exampleInputEmail1">Location</label>
<select class="form-control h-25 text-white" name="location">
<option class="text-dark" value="">--Select--</option>
<option <?php if( $single_data['location'] == 'Dhaka'){ echo "selected"; } ?> class="text-dark" value="Dhaka">Dhaka</option>
<option <?php if( $single_data['location'] == 'Barisal'){ echo "selected"; } ?> class="text-dark" value="Barisal">Barisal</option>
<option <?php if( $single_data['location'] == 'chittagong'){ echo "selected"; } ?> class="text-dark" value="chittagong">chittagong</option>
<option <?php if( $single_data['location'] == 'Khulna'){ echo "selected"; } ?> class="text-dark" value="Khulna">Khulna</option>
<option <?php if( $single_data['location'] == 'Mymensignh'){ echo "selected"; } ?> class="text-dark" value="Mymensignh">Mymensignh</option>
<option <?php if( $single_data['location'] == 'Rangpur'){ echo "selected"; } ?> class="text-dark" value="Rangpur">Rangpur</option>
<option <?php if( $single_data['location'] == 'Sylhet'){ echo "selected"; } ?> class="text-dark" value="Sylhet">Sylhet</option>
</select>
</div>
<div class="form-group">
<img style="width: 100px;" src="photo/students/<?php echo $single_data['photo']; ?>" alt="">
<input name="old_photo" value="<?php echo $single_data['photo']; ?>" type="hidden">
</div>
<div class="form-group ">
<label for="exampleInputEmail1">Photo</label>
<input name="new_photo" type="file" class="form-control-file text-white">
</div>
<button name="add" type="submit" class="btn btn-primary">Update Now</button>
</form>
</div>
<script src="assets/js/jquery-3.5.1.slim.min.js"></script>
<script src="assets/js/popper.min.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
<script>
</script>
</body>
</html>