<?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['departmentid'])) {

    $departmentid = mysqli_real_escape_string($db,$_POST['departmentid']);
    $department_name = mysqli_real_escape_string($db,$_POST['department_name']);

    $sqlUpdateDepartment = "
    UPDATE departments
    SET departmentname = '$department_name'
    WHERE departmentid = $departmentid;";


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

      $departmentUpdate = "User updated department ";

      logEvent($db,"Department updated",$departmentUpdate,$last_id);
      
      header("location: departments.php");

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

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

?>