-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupdate.php
More file actions
70 lines (58 loc) · 2.45 KB
/
Copy pathupdate.php
File metadata and controls
70 lines (58 loc) · 2.45 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
<?php
session_start();
// Include database connection (replace with your credentials)
include('./admin/config.php');
$user_id = $_SESSION['user_id'];
$first_name = sanitize_input($_POST['fname']);
$last_name = sanitize_input($_POST['lname']);
$phone = sanitize_input($_POST['phone']);
$cabin = sanitize_input($_POST['faculty-cabin']);
$ext = sanitize_input($_POST['faculty-ext']);
if(empty($cabin) && empty($ext)){
$utype = 'student';
} else {
$utype = 'faculty';
}
// Update user details (excluding email)
$sql = "UPDATE registered_user SET fname = ?, lname = ?, phone = ?,faculty_cabin = ?,faculty_extension = ? , user_type = ? WHERE user_id = ?";
$stmt = mysqli_prepare($conn, $sql);
mysqli_stmt_bind_param($stmt, "ssssssi", $first_name, $last_name, $phone,$cabin, $ext, $utype, $user_id);
$result = mysqli_stmt_execute($stmt);
if ($result) {
$_SESSION['success'] = "Profile details updated successfully!"; // Success message
} else {
$_SESSION['error'] = "Error updating profile: " . mysqli_error($conn); // Error message
}
mysqli_stmt_close($stmt);
// Handle password change (optional)
if (!empty($_POST['new_password']) && !empty($_POST['confirm_password'])) {
// Verify current password before updating
$sql = "SELECT pass FROM registered_user WHERE user_id = ?";
$stmt = mysqli_prepare($conn, $sql);
mysqli_stmt_bind_param($stmt, "i", $user_id); // bind param with int
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$user = mysqli_fetch_assoc($result);
if ($_POST['new_password']==$_POST['confirm_password']) {
// Hash new password before update
$new_password = password_hash($_POST['new_password'], PASSWORD_DEFAULT);
$sql = "UPDATE registered_user SET pass = ? WHERE user_id = ?";
$stmt = mysqli_prepare($conn, $sql);
mysqli_stmt_bind_param($stmt, "si", $new_password, $user_id);
$result = mysqli_stmt_execute($stmt);
if ($result) {
$_SESSION['success'] .= "<br>Password changed successfully!";
} else {
$_SESSION['error'] .= "<br>Error updating password: " . mysqli_error($conn);
}
} else {
$_SESSION['error'] .= "<br> Cannot update password: Password do not match ";
}
mysqli_stmt_close($stmt);
}
// Handle adding default payment system (optional)
mysqli_close($conn); // Close connection
// Redirect to profile page after processing
header("Location: profile.php");
exit();
?>