-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddress.php
More file actions
178 lines (152 loc) · 5.35 KB
/
Copy pathaddress.php
File metadata and controls
178 lines (152 loc) · 5.35 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
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
<?php
session_start();
include 'db_connection.php';
if (!isset($_SESSION['username'])) {
header("Location: index.html"); // Jump to login page if not logged in
exit();
}
$current_username = $_SESSION['username'];
//Start timing
$start_time = microtime(true);
// Query current address
$stmt = $conn->prepare("SELECT address FROM users WHERE username=?");
$stmt->bind_param("s", $current_username);
$stmt->execute();
$result = $stmt->get_result();
$user_data = $result->fetch_assoc();
$current_address = $user_data['address'] ?? 'Not available'; // If there is no address, the default message is displayed
$stmt->close();
// Processing change-of-address requests
if (isset($_POST['update_address'])) {
$new_address = $_POST['new_address']; // new address
// Updating addresses in the database
$stmt = $conn->prepare("UPDATE users SET address=? WHERE username=?");
$stmt->bind_param("ss", $new_address, $current_username);
if ($stmt->execute()) {
echo "<script>alert('Address updated successfully.'); window.location.href='profile.php';</script>";
} else {
echo "<script>alert('An error occurred while updating the address.');</script>";
}
$stmt->close();
$conn->close();
}
$end_time = microtime(true);
$execution_time = round(($end_time - $start_time) * 1000, 2); //Convert to milliseconds
?>
<!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="./css/dashboard.css" />
<link rel="icon" href="assets/logo.png" type="image/png">
<title>Update Address | GBC Internet Banking</title>
<style>
.form-container {
max-width: 600px;
margin: 50px auto;
padding: 20px;
background-color: #fff;
box-shadow: 0 1px 6px rgba(0, 0, 0, 0.1);
border-radius: 8px;
}
.form-container h2 {
text-align: center;
font-size: 24px;
margin-bottom: 20px;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
font-size: 16px;
display: block;
margin-bottom: 8px;
}
.form-group input {
width: 100%;
padding: 10px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 4px;
}
.form-group input[type="submit"] {
background-color: #4ba247;
color: white;
border: none;
cursor: pointer;
font-weight: bold;
}
.form-group input[type="submit"]:hover {
background-color: #45a047;
}
.current-address {
font-size: 16px;
color: #333;
margin-bottom: 20px;
padding: 10px;
background-color: #f7f7f7;
border-radius: 5px;
}
.back-link {
text-align: center;
margin-top: 20px;
}
.back-link a {
text-decoration: none;
color: #0064d2;
}
</style>
</head>
<body>
<!-- Header -->
<header class="header">
<div class="header__content">
<div class="header__logo">
<a href="./dashboard.php"><img src="./assets/logo.png" alt="Bank Logo"></a>
</div>
<h1>Welcome to GBC Internet Banking</h1>
<div class="header__right">
Current User: <?php echo htmlspecialchars($_SESSION['username']); ?>
<button class="logout-button" style="margin-left: 10px;" onclick="window.location.href='logout.php'">Logout</button>
</div>
</div>
</header>
<!-- Main Content -->
<main class="dashboard">
<div class="form-container">
<h2>Update Your Address</h2>
<!-- Display current address -->
<div class="current-address">
<strong>Current Address:</strong><br> <?php echo htmlspecialchars($current_address); ?>
</div>
<!-- Modify Address Form -->
<form method="post" action="">
<div class="form-group">
<label for="new_address">New Address:</label>
<input
autocomplete="off"
type="text"
placeholder="Enter your new address"
name="new_address"
class="field__input"
required
/>
</div>
<div class="form-group">
<input type="submit" name="update_address" value="Update Address">
</div>
</form>
<div class="back-link">
<p><a href="javascript:history.back()">Return to the previous page</a></p>
</div>
</div>
</main>
<footer class="footer">
<?php if ($execution_time): ?>
It took <?php echo $execution_time; ?> milliseconds to get data from the server.</p>
<?php endif; ?>
©2024 Global Banking Corporation Limited. All rights reserved.
</footer>
</body>
</html>