<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

if (isset($_POST['RegWorker'])) {
if (!empty($_POST['Fullname']) && !empty($_POST['AccType']) && !empty($_POST['AccBal']) && !empty($_POST['Password']) ) {
 require 'connect.php';
$Username = mysqli_real_escape_string($connect, htmlentities($_POST['Username']));
$Username = trim($Username);
$Email = mysqli_real_escape_string($connect, htmlentities($_POST['Email']));
$Phone = mysqli_real_escape_string($connect, htmlentities($_POST['Phone']));
$Fullname = mysqli_real_escape_string($connect, htmlentities($_POST['Fullname']));
$AccNum = rand(0234726334,9999999999);
$AccType = mysqli_real_escape_string($connect, htmlentities($_POST['AccType']));
$AccBal = mysqli_real_escape_string($connect, htmlentities($_POST['AccBal']));
$Password = mysqli_real_escape_string($connect, htmlentities($_POST['Password']));
$imageName = $_FILES['file']['name'];
$sourcePath = $_FILES['file']['tmp_name'];       // Storing source path of the file in a variable
$targetPath = "AccImage/".$_FILES['file']['name']; // Target path where file is to be stored
$pageKey = rand(0, 1919011);

$Curr = ($_POST['curr']);


if (move_uploaded_file($sourcePath,$targetPath)) {
$insert = mysqli_query($connect, "INSERT INTO customers(ID, Username, Email, active, Phone, AccFullname, AccNum, AccBal, Curr, AccType,  AccImage, LastLogin, PageKey, Password, Admin, TransControl, allowed) 
VALUES(NULL, '$Username','$Email', 1, '$Phone', '$Fullname','$AccNum', '$AccBal', '$Curr', '$AccType', '$imageName', NOW(), '$pageKey', '$Password', 0, 0, 0)");
if ($insert) {
header("Location: /personal-access/admin/");
echo "<span style='text-align: center; display: block; color: green; line-height: 2;'>SUCCESS</span>";
// === email ====

}else {
echo '<span style="text-align:center; color: red; display: block; line-height: 2;">An Error occurred, Could not register customer</span>';
}

}else {
echo '<span style="text-align:center; color: red; display: block; line-height: 2;"> Could not upload image</span>';
}

}
else {
echo '<span style="text-align:center; color: red; display: block; line-height: 2;"> All fields here are important</span>';
}

}





?>

