-
Notifications
You must be signed in to change notification settings - Fork 0
/
userDataUpdate.php
218 lines (180 loc) · 7.34 KB
/
userDataUpdate.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
<?php
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fetch Data by ID</title>
<style>
body {
font-family: 'Arial', sans-serif;
background-color: #f8f9fa;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
background-color: #ffffff;
border: 1px solid #ced4da;
border-radius: 5px;
padding: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h2 {
color: #007bff;
margin-bottom: 20px;
}
form {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items:center;
margin:30px;
}
.form-group {
flex-basis: calc(33.33% - 10px);
margin-bottom: 15px;
}
label {
font-weight: bold;
display: block;
margin-bottom: 5px;
}
input, select {
width: 100%;
padding: 10px;
box-sizing: border-box;
border:none;
border-radius: 4px;
background-color: #f8f9fa;
}
input[type="text"] {
font-size: 16px;
color: #495057;
cursor: not-allowed;
}
input[type="submit"] {
background-color: #007bff;
color: #fff;
cursor: pointer;
transition: background-color 0.3s ease;
}
input[type="submit"]:hover {
background-color: #0056b3;
}
.editableField{
input, select{
border: 2px solid #ced4da;
cursor: text;
}
}
</style>
</head>
<body>
<div class="container">
<?php
include_once('db_connection_short.php');
$id = $_SESSION['id'];
// Query to fetch data by ID
$sql = "SELECT * FROM users WHERE id = $id";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// Display form with fetched data
$row = $result->fetch_assoc();
?>
<h2>Update Panel for ID:
<?php echo $row['id']; ?>
</h2>
<form action="update_process.php" method="post">
<div class="form-group">
<label for="id">ID:</label>
<input type="text" id="id" name="id" value="<?php echo $row['id']; ?>" readonly>
</div>
<div class="form-group editableField">
<label for="name">Name:</label>
<input type="text" id="name" name="name" value="<?php echo $row['name']; ?>">
</div>
<div class="form-group editableField">
<label for="age">DOB:</label>
<input type="date" id="dob" name="dob" value="<?php echo $row['dob']; ?>">
</div>
<div class="form-group">
<label for="age">Age:</label>
<input type="text" id="age" name="age" value="<?php echo $row['age']; ?>" readonly>
</div>
<div class="form-group editableField">
<label for="gender">Gender:</label>
<select name="gender" required>
<option value="Male" <?php echo ($row['gender'] === 'Male') ? 'selected' : ''; ?>>Male</option>
<option value="Female" <?php echo ($row['gender'] === 'Female') ? 'selected' : ''; ?>>Female</option>
<option value="Prefer not to say" <?php echo ($row['gender'] === 'Prefer not to say') ? 'selected' : ''; ?>>Prefer not to say</option>
</select>
</div>
<div class="form-group editableField">
<label for="blood_group">Blood Group:</label>
<select name="blood_group" required>
<option value="A+" <?php echo ($row['blood_group'] === 'A+') ? 'selected' : ''; ?>>A+</option>
<option value="B+" <?php echo ($row['blood_group'] === 'B+') ? 'selected' : ''; ?>>B+</option>
<option value="AB+" <?php echo ($row['blood_group'] === 'AB+') ? 'selected' : ''; ?>>AB+</option>
<option value="O+" <?php echo ($row['blood_group'] === 'O+') ? 'selected' : ''; ?>>O+</option>
<option value="A-" <?php echo ($row['blood_group'] === 'A-') ? 'selected' : ''; ?>>A-</option>
<option value="B-" <?php echo ($row['blood_group'] === 'B-') ? 'selected' : ''; ?>>B-</option>
<option value="AB-" <?php echo ($row['blood_group'] === 'AB-') ? 'selected' : ''; ?>>AB-</option>
<option value="O-" <?php echo ($row['blood_group'] === 'O-') ? 'selected' : ''; ?>>O-</option>
</select>
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="text" id="email" name="email" value="<?php echo $row['email']; ?>" readonly>
</div>
<div class="form-group editableField">
<label for="mobile_number">Mobile Number:</label>
<input type="text" id="mobile_number" name="mobile_number" value="<?php echo $row['mobile_number']; ?>">
</div>
<div class="form-group editableField">
<label for="city">City:</label>
<input type="text" id="city" name="city" value="<?php echo $row['city']; ?>">
</div>
<!-- <div class="form_group"> -->
<input type="submit" value="Update">
<!-- </div> -->
</form>
<?php
} else {
echo "<h2>No data found for ID: $id</h2>";
}
$conn->close();
?>
</div>
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<script>
const maxDate = new Date();
maxDate.setFullYear(maxDate.getFullYear() - 18);
const formattedMaxDate = maxDate.toISOString().split('T')[0];
document.getElementById('dob').setAttribute('max', formattedMaxDate);
$(document).ready(function () {
// Function to calculate age based on DOB
function calculateAge() {
var dob = new Date($('#dob').val());
var today = new Date();
var age = today.getFullYear() - dob.getFullYear();
// Adjust age if birthday hasn't occurred yet this year
if (today.getMonth() < dob.getMonth() || (today.getMonth() === dob.getMonth() && today.getDate() < dob.getDate())) {
age--;
}
// Set the calculated age to the age input field
$('#age').val(age);
}
// Attach event listener to the DOB input
$('#dob').change(calculateAge);
// Initial calculation on page load
calculateAge();
});
</script>
</body>
</html>