<?php
###### db ##########
$db_username = 'root';
$db_password = 'AkuTerimaNikahnya';
$db_name = 'picc';
//$db_username = 'picccom_picc';
//$db_password = '@kuTerimaNikahnya';
//$db_name = 'picccom_picc';
$db_host = 'localhost';
################


//check we have username post var
if(isset($_POST["username"]))
{
	//check if its ajax request, exit script if its not
	if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND $_SERVER['HTTP_X_REQUESTED_WITH'] != 'xmlhttprequest') {
		die();
	}
	
	//try connect to db
	$connecDB = mysqli_connect($db_host, $db_username, $db_password,$db_name)or die('could not connect to database');
	
	//trim and lowercase username
	//$username =  strtolower(trim($_POST["username"])); 
	$username =  $_POST["username"]; 
	
	//sanitize username
	//$username = filter_var($username, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW|FILTER_FLAG_STRIP_HIGH);

	$username = filter_var($username, FILTER_SANITIZE_STRING);
	
	//check username in db
	$results = mysqli_query($connecDB,"SELECT CUST_USERNAME FROM customers WHERE CUST_USERNAME ='$username'");
	
	//return total count
	$username_exist = mysqli_num_rows($results); //total records
	
	//if value is more than 0, username is not available
	if($username_exist) {
		include_once('booking_contact_exist.php');
		die();
	}else{
		include_once('booking_contact_include.php');
		die();
	}
	
	//close db connection
	mysqli_close($connecDB);
}
?>

