-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsave_password.php
31 lines (25 loc) · 1005 Bytes
/
save_password.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
<?php
// save_password.php
include("connection.php"); // Make sure to include your database connection file
session_start();
if (isset($_SESSION['email'])) {
$email = $_SESSION['email'];
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Validate and sanitize the new password
$newPassword = isset($_POST['newPassword']) ? htmlspecialchars($_POST['newPassword']) : '';
// Update the password in the database
$sql = "UPDATE user_details SET password = '$newPassword' WHERE email = '$email'";
if ($conn->query($sql) === TRUE) {
echo "Password updated successfully";
} else {
echo "Error updating password: " . $conn->error;
}
} else {
echo "Invalid request method";
}
} else {
// Redirect the user to the login page if not logged in
header("Location: about.php");
exit();
}
?>