-
Notifications
You must be signed in to change notification settings - Fork 0
/
Alumni_Portal_Details.php
67 lines (58 loc) · 2.4 KB
/
Alumni_Portal_Details.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
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
<?php
session_start(); // Start the session
// // Configuration settings for database connection
// $servername = "localhost"; // Update with your database servername
// $username = "root"; // Update with your database username
// $password = "password"; // Update with your database password
// $dbname = "TPC"; // Update with your database name
require 'config.php';
// Create a connection to the database
// $conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// Check if user is logged in
if (!isset($_SESSION['user_id'])) {
// Redirect to login page if not logged in
header("Location: Alumni_Login.html");
exit;
}
// Get the user ID from session
$roll_number = $_SESSION['user_id'];
// Check if form is submitted
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Get form data
$firstname = $_POST['first_name'];
$lastname = $_POST['last_name'];
$password = $_POST['password'];
$confirm_password = $_POST['confirm_password'];
$email = $_POST['email'];
// Add other fields as needed
// Check if password and confirm password match
if ($password !== $confirm_password) {
// Show error message
echo "Error: Password and Confirm Password do not match!";
} else {
// Hash the password
$hashed = password_hash($password, PASSWORD_DEFAULT);
// Update the alumni profile details in the database
// Assuming you have a database connection already established
// Only update fields that have changed
$sql = "UPDATE alumni_login SET
password = ". ($password ? "'$hashed'" : 'password') .",
email = ". ($email ? "'$email'" : 'email') .",
first_name = ". ($firstname ? "'$firstname'" : 'first_name') .",
last_name = ". ($lastname ? "'$lastname'" : 'last_name') ."
WHERE roll_number = '$roll_number'";
$result = $conn->query($sql);
if ($result) {
// Success message
echo '<script type="text/javascript">alert("Profile details updated successfully!")</script>';
echo '<script language="javascript">window.location = "http://localhost/miniproject_dbms/Alumni_Welcome.php";</script>';
} else {
// Error message
echo "Error: Failed to update profile details.";
}
}
}
?>