Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include '../../../DatabaseController/conn.php';
- $conn = $pdo->open();
- $stmt = $conn->prepare("SELECT * FROM users
- LEFT JOIN user_title ON users.title_id = user_title.title_id
- LEFT JOIN user_dept ON users.department_id = user_dept.department_id
- LEFT JOIN user_position ON users.position_id = user_position.position_id
- WHERE id=:id");
- $stmt->execute(['id'=>$_SESSION['user_id']]);
- $user = $stmt->fetch();
- if(isset($_POST['save'])){
- $curr_password = $_POST['curr_password'];
- $select_title = $_POST['select_title'];
- $select_department = $_POST['select_department'];
- $select_position = $_POST['select_position'];
- $firstname = $_POST['firstname'];
- $lastname = $_POST['lastname'];
- $email = $_POST['email'];
- $password = $_POST['password'];
- $photo = $_FILES['photo']['name'];
- if(password_verify($curr_password, $user['password'])){
- if(!empty($photo)){
- //New Feature
- $tmp_name = $_FILES['photo']['tmp_name'];
- $path = $_SERVER['DOCUMENT_ROOT'].'/OneTrinity/styles/dashboard/user-img/';
- $dirWPhoto = $path.$photo;
- if (move_uploaded_file($tmp_name, $dirWPhoto))
- {
- $filename = $photo;
- }
- }
- else
- {
- $filename = $user['photo'];
- }
- if ($password == $user['password'])
- {
- $password = $user['password'];
- // echo "Same Password";
- }
- else
- {
- $password = password_hash($password);
- // echo "New Password";
- }
- $stmt1 = $conn->prepare("UPDATE users SET title_id=:title_id,
- department_id=:department_id, position_id=:position_id, email=:email,
- password=:password, firstName=:firstName, lastName=:lastName, photo=:photo
- WHERE id =:id
- ");
- $stmt1->execute(['title_id'=>$select_title,
- 'department_id'=>$select_department,
- 'position_id'=>$select_position,
- 'email'=>$email,
- 'password'=>$password,
- 'firstName'=>$firstname,
- 'lastName'=>$lastname,
- 'photo'=>$filename,
- 'id'=>$user['id'],
- ]);
- $_SESSION['success'] = 'Account updated successfully!!';
- }
- else
- {
- $_SESSION['error'] = 'Incorrect password';
- }
- }
- header('Location: ../../../Users/Admin/users.php');
- $pdo->close();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement