<?php

require_once 'config.php';
//$error=false;
$errors=array();

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
	
    $username = $_POST['username'];
    $passwd = $_POST['password'];
    // $passwd=  md5($passwd);
   
	$query = "SELECT * FROM users WHERE (email='".$username."' OR phone='".$username."') AND password='".$passwd."'   AND status=1";
	
	
    $row = mysqli_query($con,$query);
     
    if (mysqli_num_rows($row) >= 1) { 
		while($r=mysqli_fetch_array($row)){
			
			$errors['user_id'] = $r['id'];
			$errors['role']=$r['role'];
			$errors['nick_name']=$r['first_name'];
			$errors['phone']=$r['phone'];
			$errors['first_name']=$r['first_name'];
			$errors['last_name']=$r['last_name'];
			$errors['email']=$r['email'];
			$errors['address']=$r['address'];
			$errors['city']=$r['city'];
			$errors['pincode']=$r['pincode'];
			$errors['unit_no']=$r['unit_no'];
			$errors['floor']=$r['floor'];
			$country_id = mysqli_fetch_array(mysqli_query($con,"SELECT * FROM `countries` where id=".$r['country_id']));
			$errors['country'] =$country_id['name'];
		}
		$errors['success']='User successfully Logedin';
    } else {
        //$error=true;
		$errors['success']='Userid and password are Wrong !!';
    }
	echo json_encode($errors);
  
}

?>