-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit_profile.php
More file actions
140 lines (127 loc) · 5.51 KB
/
edit_profile.php
File metadata and controls
140 lines (127 loc) · 5.51 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
<?php
session_start();
if (!isset($_SESSION['voter_id'])) {
header("Location: login.php");
exit();
}
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "weDecideDB";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$voter_id = $_SESSION['voter_id'];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$phone = $_POST['phone'];
$email = $_POST['email'];
$new_password = $_POST['new_password'];
$confirm_password = $_POST['confirm_password'];
$check_email_stmt = $conn->prepare("SELECT voter_id FROM voters WHERE email = ? AND voter_id != ?");
$check_email_stmt->bind_param("si", $email, $voter_id);
$check_email_stmt->execute();
$check_email_stmt->store_result();
if ($check_email_stmt->num_rows > 0) {
echo "Email already exists! Please use a different email.";
} else {
$stmt = $conn->prepare("UPDATE voters SET phone = ?, email = ? WHERE voter_id = ?");
$stmt->bind_param("ssi", $phone, $email, $voter_id);
if (!$stmt->execute()) {
echo "Error updating phone and email: " . $stmt->error;
}
$stmt->close();
if (!empty($new_password)) {
if ($new_password === $confirm_password) {
$hashed_password = password_hash($new_password, PASSWORD_DEFAULT);
$stmt = $conn->prepare("UPDATE voters SET password = ? WHERE voter_id = ?");
$stmt->bind_param("si", $hashed_password, $voter_id);
if (!$stmt->execute()) {
echo "Error updating password: " . $stmt->error;
}
$stmt->close();
} else {
echo "Passwords do not match!";
}
}
header("Location: home.php");
exit();
}
$check_email_stmt->close();
} else {
$stmt = $conn->prepare("SELECT first_name, last_name, gender, dob, phone, email, nin FROM voters WHERE voter_id = ?");
$stmt->bind_param("s", $voter_id);
$stmt->execute();
$stmt->bind_result($first_name, $last_name, $gender, $dob, $phone, $email, $nin);
$stmt->fetch();
$stmt->close();
}
$conn->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>weDecide | Edit Profile - <?php echo htmlspecialchars($first_name); ?> <?php echo htmlspecialchars($last_name); ?></title>
<link rel="stylesheet" href="assets/css/style.css" />
</head>
<body>
<?php include 'include/header.php'?>
<div class="edit-profile-container">
<h2>Edit Profile</h2>
<form action="edit_profile.php" method="POST">
<div class="form-row">
<div class="form-group">
<label for="first_name">First Name:</label>
<input type="text" id="first_name" name="first_name" value="<?php echo htmlspecialchars($first_name); ?>" disabled />
</div>
<div class="form-group">
<label for="last_name">Last Name:</label>
<input type="text" id="last_name" name="last_name" value="<?php echo htmlspecialchars($last_name); ?>" disabled />
</div>
</div>
<div class="form-row">
<div class="form-group">
<label for="dob">Date of Birth:</label>
<input type="text" id="dob" name="dob" value="<?php echo htmlspecialchars($dob); ?>" disabled />
</div>
<div class="form-group">
<label for="gender">Gender:</label>
<input type="text" id="gender" name="gender" value="<?php echo htmlspecialchars(ucfirst($gender)); ?>" disabled />
</div>
</div><div class="form-group full-width">
<label for="profile_picture">Upload Profile Picture:</label>
<input type="file" id="profile_picture" name="profile_picture" required/>
</div>
<div class="form-group full-width">
<label for="nin">National Identification Number (NIN):</label>
<input type="text" id="nin" name="nin" value="<?php echo htmlspecialchars($nin); ?>" disabled />
</div>
<div class="form-row">
<div class="form-group">
<label for="email">Email:</label>
<input type="email" id="email" name="email" value="<?php echo htmlspecialchars($email); ?>" required />
</div>
<div class="form-group">
<label for="phone">Mobile Number:</label>
<input type="text" id="phone" name="phone" value="<?php echo htmlspecialchars($phone); ?>" required />
</div>
</div>
<div class="form-row">
<div class="form-group">
<label for="new_password">Enter Password:</label>
<input type="password" id="new_password" name="new_password" placeholder="Enter New Password" />
</div>
<div class="form-group">
<label for="confirm_password">Confirm Password:</label>
<input type="password" id="confirm_password" name="confirm_password" placeholder="Confirm New Password" />
</div>
</div>
<button type="submit">SAVE</button>
</form>
<a href="home.php" class="cancelBtn">CANCEL</a>
</div>
<script src="assets/js/script.js"></script>
</body>
</html>