<?php
   include('session.php');
   include('connect.php');
   include('logging.php');

// start role specific 
$user_role = $_SESSION['role'];

if ($_SERVER["REQUEST_METHOD"] == "POST") {

  if (isset($_POST['userid'])) {

    $userid = mysqli_real_escape_string($db,$_POST['userid']);
    $password = mysqli_real_escape_string($db,$_POST['password']);
    $password = md5($password);

    $sqlUpdatePassword = "
    UPDATE users
    SET password = '$password'
    WHERE userid = $userid;";


      if(mysqli_query($db, $sqlUpdatePassword)) {

      $userPasswordUpdate = "User updated user password";

      logEvent($db,"Password updated",$userPasswordUpdate,$last_id);
      
      header("location: usersmanagement.php?updated=2");

      } else {
         echo "Error: " . mysqli_error($db);
    }

    } else {
    echo "User not selected!!!";
   }
 
}

?>