-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprofile.php
More file actions
197 lines (177 loc) · 7.15 KB
/
profile.php
File metadata and controls
197 lines (177 loc) · 7.15 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php
session_start();
$username = $_SESSION['username'];
require_once 'includes/dbh.inc.php';
if (!isset($username)) {
header('location: login.php');
}
$sql = "SELECT * FROM user WHERE userUsername = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $username);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$fName = $row["userFname"];
$lName = $row["userLname"];
$address = $row["userAddress"];
$email = $row["userEmail"];
$phone = $row["userPhone"];
$username = $row["userUsername"];
$pwd = $row["userPwd"];
} else {
echo "<html><head></head><body><script>
alert ('Please log in');
window.location.href='signup.php';
</script>
</body>
</html>";
exit();
}
if (isset($_POST['update-profile'])) {
$newFName = $_POST['new-first-name'];
$newLName = $_POST['new-last-name'];
$newAddress = $_POST['new-address'];
$newEmail = $_POST['new-email'];
$newPhone = $_POST['new-phone'];
$newpwd = $_POST["new-userPwd"];
// Update user details
$updateSql = "UPDATE user SET userFname = ?, userLname = ?, userAddress = ?, userEmail = ?, userPhone = ?, userPwd = ? WHERE userUsername = ?";
$stmt = $conn->prepare($updateSql);
$stmt->bind_param("sssssss", $newFName, $newLName, $newAddress, $newEmail, $newPhone, $newpwd, $username);
if ($stmt->execute()) {
echo "<html><head></head><body><script>
alert ('Update successful');
window.location.href = 'profile.php';
</script>
</body>
</html>";
} else {
echo "Update failed: " . $stmt->error;
}
$stmt->close();
}
if (isset($_POST['delete-account'])) {
// Perform the account deletion
$deleteSql = "DELETE FROM user WHERE userUsername = ?";
$stmt = $conn->prepare($deleteSql);
$stmt->bind_param("s", $username);
if ($stmt->execute()) {
session_unset();
session_destroy();
echo "<html><head></head><body><script>
alert ('Account deleted successfully!');
window.location.href='index.php';
</script>
</body>
</html>";
} else {
echo "Account deletion failed: " . $stmt->error;
}
$stmt->close();
}
if (isset($_POST['logout'])) {
// Clear the session and log the user out
session_unset();
session_destroy();
header('location: login.php');
exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Construction Management site</title>
<link rel="stylesheet" href="styles/styles.css">
<link rel="stylesheet" href="styles/profileStyles.css">
</head>
<body>
<!-- Header Section -->
<div class="header">
<nav>
<img src="logo.png" alt="Construction Management Logo">
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="#about">Our Services</a></li>
<li><a href="#services">Our Projects</a></li>
<li><a href="#blog">Contact Us</a></li>
<li><a href="#contact">About Us</a></li>
<?php
// Check if the user is logged in
if (isset($_SESSION['username'])) {
// If logged in, display "My Profile" and "Logout" links
echo '<li><a href="logout.php">My Projects</a></li>';
echo '<li><a href="profile.php">My Profile</a></li>';
} else {
// If not logged in, display "Register" and "Login" links
echo '<li><a href="signup.php">Register</a></li>';
echo '<li><a href="login.php">Login</a></li>';
}
?>
</ul>
</nav>
</div>
<div class="outer-box">
<div class="My-Profile-container">
<h1>My Profile</h1>
<img src="images/blank-profile-picture-973460_1280.png" alt="User Profile Picture" class="profile-picture">
<p class="username">Username: <?php echo $username; ?></p>
<form method="POST" action="">
<button class="logout-button" name="logout">Log Out</button> <!-- Log Out button -->
</form>
<p>
<h3>Account Details</h3>
</p>
<p>First Name: <?php echo $fName; ?></p>
<p>Last Name: <?php echo $lName; ?></p>
<p>Address: <?php echo $address; ?></p>
<p>Email: <?php echo $email; ?></p>
<p>Phone Number: <?php echo $phone; ?></p>
</div>
</div>
<div class="outer-box">
<div class="Manage-Account-container">
<h2 class="Manage-Account-title">Manage Account</h2>
<form method="POST" action="" enctype="multipart/form-data"> <!-- Added enctype attribute for file uploads -->
<div class="account-info">
<div class="account-detail">
<label for="new-first-name">First Name:</label>
<input type="text" id="new-first-name" name="new-first-name" value="<?php echo $fName; ?>">
<button class="update-button" name="update-profile">Update</button>
</div>
<div class="account-detail">
<label for="new-last-name">Last Name:</label>
<input type="text" id="new-last-name" name="new-last-name" value="<?php echo $lName; ?>">
<button class="update-button" name="update-profile">Update</button>
</div>
<div class="account-detail">
<label for="new-address">Address:</label>
<input type="text" id="new-address" name="new-address" value="<?php echo $address; ?>">
<button class="update-button" name="update-profile">Update</button>
</div>
<div class="account-detail">
<label for="new-email">Email:</label>
<input type="text" id="new-email" name="new-email" value="<?php echo $email; ?>">
<button class="update-button" name="update-profile">Update</button>
</div>
<div class = "account-detail">
<label for="new-phone">Phone Number:</label>
<input type="text" id="new-phone" name="new-phone" value="<?php echo $phone; ?>">
<button class="update-button" name="update-profile">Update</button>
</div>
<div class = "account-detail">
<label for="new-userPwd">Password:</label>
<input type="text" id="new-userPwd" name="new-userPwd" value="<?php echo $pwd; ?>">
<button class="update-button" name="update-profile">Update</button>
</div>
<div class="account-detail">
<button class="delete-button" name="delete-account">Delete Account</button>
</div>
</div>
</form>
</div>
</div>
</body>
</html>