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

    $employee_id = mysqli_real_escape_string($db,$_POST['employee_id']);
    $employee_basic_salary = mysqli_real_escape_string($db,$_POST['employee_basic_salary']);
    $employee_travelling = mysqli_real_escape_string($db,$_POST['employee_travelling']);

    $sqlAddEmployeeJob = "INSERT INTO salaries (
      employeeid,
      salaryvalue,
      latest
      ) VALUES (
      '$employee_id',
      '$employee_basic_salary',
      '1');";

      $sqlAddEmployeeTravelling = "INSERT INTO travellings (
      employeeid,
      travellingvalue,
      latest
      ) VALUES (
      '$employee_id',
      '$employee_travelling',
      '1');";

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

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

      $employeeUpdate = "User updated employee ";

      logEvent($db,"Employee updated",$employeeUpdate,$last_id);
      
      header("location: viewEmployee.php?employeeID=$employee_id");

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

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

?>