Advertisement
Guest User

profile_update.php

a guest
Jan 7th, 2019
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.27 KB | None | 0 0
  1. <?php
  2.     include '../../../DatabaseController/conn.php';
  3.  
  4.     $conn = $pdo->open();
  5.  
  6.     $stmt = $conn->prepare("SELECT * FROM users
  7.                             LEFT JOIN user_title ON users.title_id = user_title.title_id
  8.                             LEFT JOIN user_dept ON users.department_id = user_dept.department_id
  9.                             LEFT JOIN user_position ON users.position_id = user_position.position_id
  10.                             WHERE id=:id");
  11.     $stmt->execute(['id'=>$_SESSION['user_id']]);
  12.  
  13.     $user = $stmt->fetch();
  14.  
  15.     if(isset($_POST['save'])){
  16.  
  17.         $curr_password = $_POST['curr_password'];
  18.  
  19.         $select_title = $_POST['select_title'];
  20.  
  21.         $select_department = $_POST['select_department'];
  22.  
  23.         $select_position = $_POST['select_position'];
  24.  
  25.         $firstname = $_POST['firstname'];
  26.  
  27.         $lastname = $_POST['lastname'];
  28.  
  29.         $email = $_POST['email'];
  30.  
  31.         $password = $_POST['password'];
  32.  
  33.         $photo = $_FILES['photo']['name'];
  34.  
  35.         if(password_verify($curr_password, $user['password'])){
  36.  
  37.             if(!empty($photo)){
  38.  
  39.                 //New Feature
  40.                 $tmp_name = $_FILES['photo']['tmp_name'];
  41.  
  42.                     $path = $_SERVER['DOCUMENT_ROOT'].'/OneTrinity/styles/dashboard/user-img/';
  43.  
  44.                 $dirWPhoto = $path.$photo;
  45.  
  46.                 if (move_uploaded_file($tmp_name, $dirWPhoto))
  47.                 {
  48.                     $filename = $photo;
  49.                 }
  50.             }
  51.             else
  52.             {
  53.                 $filename = $user['photo'];
  54.             }
  55.  
  56.                 if ($password == $user['password'])
  57.                 {
  58.                     $password = $user['password'];
  59.  
  60.                     // echo "Same Password";
  61.                 }
  62.                 else
  63.                 {
  64.                     $password = password_hash($password);
  65.                     // echo "New Password";
  66.                 }
  67.  
  68.                 $stmt1 = $conn->prepare("UPDATE users SET title_id=:title_id,
  69.                             department_id=:department_id, position_id=:position_id, email=:email,
  70.                             password=:password, firstName=:firstName, lastName=:lastName, photo=:photo
  71.                             WHERE id =:id
  72.                         ");
  73.                 $stmt1->execute(['title_id'=>$select_title,
  74.                         'department_id'=>$select_department,
  75.                         'position_id'=>$select_position,
  76.                         'email'=>$email,
  77.                         'password'=>$password,
  78.                         'firstName'=>$firstname,
  79.                         'lastName'=>$lastname,
  80.                         'photo'=>$filename,
  81.                         'id'=>$user['id'],
  82.                     ]);
  83.  
  84.                 $_SESSION['success'] = 'Account updated successfully!!';
  85.         }
  86.         else
  87.         {
  88.  
  89.             $_SESSION['error'] = 'Incorrect password';
  90.         }
  91.     }
  92.  
  93.     header('Location: ../../../Users/Admin/users.php');
  94.  
  95.     $pdo->close();
  96.  
  97. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement