<?php


session_start(); 
    $u_uname = '';
    if (isset($_COOKIE['auth_token']))
    {
        $u_uname = $_COOKIE['auth_token'];
    }else{
        header("location:../login.php");
    }
    
    include '../include/connection.php';
    if(isset($_POST['skip'])) 
    {
        header('Location:../allemployees.php');
    }

    $empId=$_GET['empId'];
    
    $empTitle = $_POST['empTitle'];
    $empPrevId = $_POST['empPrevId'];
    $empManager = $_POST['empManager'];
    $empDept = $_POST['empDept'];
    $empLocation= $_POST['empLocation'];
    $empHREmail = $_POST['empHREmail'];
    $empHRPhone = $_POST['empHRPhone'];
    $empStartDate = $_POST['empStartDate'];
    $empEndDate = $_POST['empEndDate'];

    $sql = "INSERT INTO `previousEmployment`(`empId`, `empTitle`, `empPrevId`, `empManager`, `empDept`, `empLocation`, `empHREmail`, `empHRPhone`, `empStartDate`, `empEndDate`)  VALUES ($empId,'$empTitle',$empPrevId,'$empManager','$empDept','$empLocation','$empHREmail',$empHRPhone,'$empStartDate','$empEndDate')";

    $result = $link->query($sql);

    if (isset($_POST['add'])) 
    {
        if($result){
            header('Location:../addEmployment.php?empId='.$empId);
        }
    }
    else if(isset($_POST['submit'])) 
    {
        if($result){
            header('Location:../allemployees.php');
        }
    }
    
?>


