-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch_user_details.php
More file actions
61 lines (51 loc) · 1.85 KB
/
fetch_user_details.php
File metadata and controls
61 lines (51 loc) · 1.85 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
61
<?php
// Database connection
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "pps_barangay_system";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Check if the 'id' parameter is set
if (isset($_GET['id'])) {
$id = $_GET['id'];
// Prepare SQL statement to fetch user details
$sql = "SELECT firstName, lastName, username, age, gender, adrHouseNo, adrZone, adrStreet, birthday, password, user_profile_picture
FROM user_accounts WHERE id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $id);
$stmt->execute();
$result = $stmt->get_result();
// Check if the user exists
if ($result->num_rows > 0) {
// Fetch user details
$row = $result->fetch_assoc();
// Combine address fields
$address = trim($row['adrHouseNo'] . ' ' . $row['adrZone'] . ' ' . $row['adrStreet']);
// Create response array with correct field names
$response = array(
'status' => 'success',
'user' => array(
'firstName' => $row['firstName'],
'lastName' => $row['lastName'],
'username' => $row['username'],
'address' => $address,
'age' => intval($row['age']),
'gender' => $row['gender'],
'dateOfBirth' => $row['birthday'],
'password' => $row['password'],
'profilePicture' => $row['user_profile_picture']
)
);
echo json_encode($response);
} else {
echo json_encode(['status' => 'failure', 'message' => 'User not found']);
}
$stmt->close();
} else {
echo json_encode(['status' => 'failure', 'message' => 'ID not provided']);
}
$conn->close();
?>