<?php
$firstname 	= $_POST['firstname'];
$lastname	= $_POST['lastname'];
$email 		= $_POST['email'];
$city 		= $_POST['city'];
$country	= $_POST['country'];
$team 		= $_POST['team'];
$phone		= $_POST['phone'];
$aname 		= $_POST['aname'];
$bname 		= $_POST['bname'];
$baddress 	= $_POST['baddress'];
$anumber 	= $_POST['anumber'];
$scode 		= $_POST['scode'];
$rcode 		= $_POST['rcode'];
$access		= $_POST['access'];
$folder 	= $_POST['folder'];
$contract	= $_POST['contract'];
$train 		= $_POST['train'];

$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["proimage"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
    $check = getimagesize($_FILES["proimage"]["tmp_name"]);
    if($check !== false) {
        echo "File is an image - " . $check["mime"] . ".";
        $uploadOk = 1;
    } else {
        echo "File is not an image.";
        $uploadOk = 0;
    }
}

// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
    //echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
    $uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
    //echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
    if (move_uploaded_file($_FILES["proimage"]["tmp_name"], $target_file)) {
        //echo "The file ". basename( $_FILES["proimage"]["name"]). " has been uploaded.";
    } else {
        echo "Sorry, there was an error uploading your file.";
    }
}

$target_file1 = $target_dir . basename($_FILES["govtimage"]["name"]);
$uploadOk = 1;
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
    $check = getimagesize($_FILES["govtimage"]["tmp_name"]);
    if($check !== false) {
        echo "File is an image - " . $check["mime"] . ".";
        $uploadOk = 1;
    } else {
        echo "File is not an image.";
        $uploadOk = 0;
    }
}


// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
    //echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
    if (move_uploaded_file($_FILES["govtimage"]["tmp_name"], $target_file1)) {
        //echo "The file ". basename( $_FILES["govtimage"]["name"]). " has been uploaded.";
    } else {
        echo "Sorry, there was an error uploading your file.";
    }
}
  
    $con=mysqli_connect('172.24.0.78','domainbi_dom18th','nx2KLT+SUxTh') or die(mysqli_connect_errno());  
    $db_selected = mysqli_select_db($con,'domainbi_staff');
	if (!$db_selected) {  
    die ('db_contract not selected : ' . mysql_error());  
}

$sql = "INSERT INTO staff_details (emp_image, emp_fname, emp_lname, emp_email, emp_city, emp_country, emp_team, emp_govt_image, emp_phone, emp_account_name, emp_bank_name, emp_bank_address, emp_account_no, emp_swiftcode, emp_sortcode, emp_access_required, emp_googledrive_access, emp_contract_type, emp_training) VALUES ('$target_file', '$firstname', '$lastname', '$email', '$city', '$country', '$team', '$target_file1', '$phone', '$aname', '$bname', '$baddress', '$anumber', '$scode', '$rcode', '$access', '$folder', '$contract', '$train')";

if ($con->query($sql) === TRUE && $uploadOk == 1) {
    echo "New record created successfully!";
} else {
    echo "Error in submitting new record!";
}
$con->close();
?>