<?php

require_once 'config.php';
$error=false;
$errors=array();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    
	//echo '<pre>';print_r($_POST);die;
	$email=$_POST['email'];
	$first_name=$_POST['nick_name'];
	 //$lastname=$_POST['last_name'];
	$mobile=$_POST['mobile'];
	//$pin_code=$_POST['pin_code'];
	$password=$_POST['password'];
	$country_id=$_POST['country_id'];
	$category=implode(',',$_POST['category']);
	
	$city=$_POST['city'];
	$role=$_POST['role'];
	
	
	
	
	if(empty($email)){
		$error=true;
		$errors['success']='Please enter email address';
	}
	
	if(empty($first_name)){
		$error=true;
		$errors['success']='Please enter first name';
	}
	
	
	if(empty($mobile)){
		$error=true;
		$errors['success']='Please enter Phone';
	}
	
	if(empty($password)){
		$error=true;
		$errors['success']='Please enter Password';
	}
	
	$checkEmailExists=mysqli_query($con,"SELECT * FROM users WHERE email='".$email."'");
	$checkEmailExists1=mysqli_query($con,"SELECT * FROM users WHERE phone='".$mobile."'");
	
	if(mysqli_num_rows($checkEmailExists)>0){
		$error=true;
		$errors['success']='Email already exists, Please try new one.';
	}
	if(mysqli_num_rows($checkEmailExists1)>0){
		$error=true;
		$errors['success']='Mobile already exists, Please try new one.';
	}
	
	
	if($error==false)
	{
		$createCustomer=mysqli_query($con,"INSERT INTO users (first_name,email,password,phone,city,country_id,category,role,status,created_at) VALUES('".$first_name."','".$email."','".$password."','".$mobile."','".$city."','".$country_id."','".$category."','3',1,'".date('Y-m-d H:i:s')."')");
		
		if($createCustomer){
			$errors['success']='Successful registered enjoy your Free Points when your phone Shake ';
			$errors['status']='true';
		}else{
			$error=true;
			$errors['success']='Something went wrong!!!, Please try again.';
			$errors['status']='false';
		}
	}
	echo json_encode($errors);
	
}
?>