<?php


include_once '../database.php';

include_once '../customers.php';

$database = new Database();

$db = $database->getConnection();

$item = new Customers($db);

if(empty($_POST['email']))

{

  echo json_encode(['status'=>'error','message'=>'email is a required field']);

  die;



}

$onboarding_query="SELECT `email` from customers WHERE `email`= '".$_POST['email']."'";

$result = $db->query($onboarding_query);

$count=$result->num_rows;

if($count>0)

{

 echo "Email Already Exist";


  die;

}
else{

        $item->name = $_POST['name'];

        $item->email = $_POST['email'];

        $item->phone = $_POST['phone'];
        $item->gs_location_id = $_POST['gs_location_id'];

        $item->created = date('Y-m-d H:i:s');

        if($item->createCustomer()){

        echo 'Employee created successfully.';

        } else{

        echo 'Employee could not be created.';

}



}



?>