<?php
session_start();
require_once("config/configDB.php"); 

function validation_input($data) {
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {

    $employeename   = stripslashes($_POST['employeename']);
    $address        = stripslashes($_POST['address']);
    $employeecode   = stripslashes($_POST['employeecode']);
    $mobile         = stripslashes($_POST['mobile']);
    $createdate  	= date("Y-m-d");
    $createdby      = $_SESSION['username'];
    $userID         = $_SESSION['user_id'];
	
	$autoinc1=mysqli_query($conn,"ALTER TABLE employee_master CHANGE id id INT(11) NOT NULL AUTO_INCREMENT ");

		$count=0;
$check_query	= mysqli_query($conn,"SELECT count(ecode) as counts FROM employee_master WHERE ecode = '$employeecode' "); // Check the database


while($row = mysqli_fetch_array($check_query)){
$count=$row['counts'];
}
if($count!=0){
// Already Exsist


		echo "<script> alert ('Data Inserted Success.');</script>";
		?>
<script language="javascript">window.location.href = "employeeMasterDashboard.php";</script>
<?php
		

}		
else
{

    $sql  = "INSERT INTO employee_master ( ename, eaddress, mobile, ecode, isdelete,createdby,userID,createdate) VALUES ('$employeename', '$address',    '$mobile', '$employeecode', '1','".$createdby."','".$userID."','".$createdate."')";

    mysqli_query($conn,$sql);

    $employeeID = mysqli_insert_id($conn);
    
    header("Location:employeeMasterDashboard.php");

}

}



?>