<?php

session_start();

if (isset($_SESSION["security_Level"]) && $_SESSION["security_Level"] < 2) {
    require_once "../Config/session_check.php";
} else {
    header("location: ../index.php");
}
$_SESSION["last_Active"] = time();

$ID = "";

if (isset($_GET["ID"])) {
    $ID = $_GET["ID"];

} else {
    header("location: ../index.php");
}


$first_err = $second_err = "";
require_once "../Config/config.php";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $nwfirst = $nwsecond = "";

    if (isset($_POST["firstN"])) {
        $nwfirst = $_POST["firstN"];
    } else {
        $first_err = "please enter the first name";
    }
    if (isset($_POST["secondN"])) {
        $nwsecond = $_POST["secondN"];
    } else {
        $second_err = "please enter the second name";
    }
    echo $first_err;
    if (empty($first_err) && empty($second_err)) {

        $WSQL = "UPDATE staff set Forename=?, Surname=? where Staff_ID=?";
        if ($stmt = mysqli_prepare($link, $WSQL)) {
            echo "dsds";


            mysqli_stmt_bind_param($stmt, "sss", $nwfirst, $nwsecond, $ID);
            // Attempt to execute the prepared statement
            if (mysqli_stmt_execute($stmt)) {
                // Close connection
                mysqli_close($link);
                header("location: ../Staff/DetailView.php?ID=" . $ID . "");
                exit;
            } else {
                echo "Something got in the way.";
            }
        }
    }

}
