<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE');
header('Access-Control-Allow-Headers: Origin, Content-Type, Accept, Authorization, X- 
Request-With');

include ('connect.php');

if(isset($_POST['name']) && isset($_POST['Email']) && isset($_POST['Mob']) && isset($_POST['city']) && isset($_POST['ip'])){

	$name = $_POST['name'];
	$email = $_POST['Email'];
	$mob = $_POST['Mob'];
	$city = $_POST['city'];
	$project_name = $_POST['Project'];
	$ip = $_POST['ip'];
	$message = (isset($_POST['message'])? $_POST['message']  : NULL );
	$gclid = (isset($_POST['gclid'])? $_POST['gclid']  : NULL );
	$calling_code = isset($_POST['calling_code'])? '+'.$_POST['calling_code']  : '+91' ;
    date_default_timezone_set("Asia/Calcutta"); 
    
    $utm_source = (isset($_POST['utm_source'])? $_POST['utm_source']  : NULL );
	$utm_medium = (isset($_POST['utm_medium'])? $_POST['utm_medium']  : NULL );
	$utm_term = (isset($_POST['utm_term'])? $_POST['utm_term']  : NULL );
	$utm_campaignID = (isset($_POST['utm_campaignID'])? $_POST['utm_campaignID']  : NULL );
	
// 	$sql = "SELECT * FROM requests where mobile = '".$mob."'";    
//     $result = mysqli_query($conn,$sql);

//     if(!mysqli_num_rows($result)){
    	

    	$sql = "INSERT INTO `requests`( `project_name`, `name`, `email`, `mobile`, `city`, `ip_address`, `device_name`, `span_status`, `request_date`, `request_datetime`,`message`,`gclid`,`calling_code`,`utm_source`,`utm_medium`,`utm_term`,`utm_campaignID`) VALUES ('".$project_name."','".$name."','".$email."','".$mob."','".$city."','".$ip."',null,'0','".date('Y-m-d')."','".date('Y-m-d H:i:s')."','".$message."','".$gclid."','".$calling_code."','".$utm_source."','".$utm_medium."','".$utm_term."','".$utm_campaignID."')";
      
        mysqli_query($conn, $sql);
        
        echo "Successfully !" ;
    	

    // }else{
    // 	echo "Mobile Number Already exist";
    // }


}else{
	echo "Working";die;
}

?>