<?php
include("../config/database.php");
$retailerExcel = $_FILES['retailerExcel']['tmp_name'];
$handle        = fopen($retailerExcel, "r");	
$c             = 0;
$cc            = 0;
while(($filesop = fgetcsv($handle, 15000, ",")) !== false)
{
	$c++;
	if($c>1)
	{														
			$ds_code	   = mysqli_escape_string($cn,trim($filesop[0])); 
			$state         = mysqli_escape_string($cn,trim($filesop[1]));
			$district      = mysqli_escape_string($cn,trim($filesop[2]));
			$sale_district = mysqli_escape_string($cn,trim($filesop[3])); 
			$beat          = mysqli_escape_string($cn,trim($filesop[4])); 
			$shop_name     = mysqli_escape_string($cn,trim($filesop[5]));
			$mobile        = mysqli_escape_string($cn,trim($filesop[6])); 																					
			$sqlProduct    = mysqli_query($cn, "INSERT INTO `tbl_retailer` SET `ds_code`='".$ds_code."', `state`='".$state."', `district`='".$district."', `sale_district`='".$sale_district."', `beat`='".$beat."', `shop_name`='".$shop_name."', `mobile`='".$mobile."', `status`=1");																	
			if($sqlProduct)
			{
				$cc++;
			}
			if($sqlProduct)
			{			
				$arr = array('status'=>true, 'SuccessMsg'=>$cc." Record Uploaded successfully. <a href='home.php?pages=viewRetailer'>Click to View</a>");
			}
			else
			{
				$arr = array('status'=>false, 'SuccessMsg'=>$cc." Record Uploaded successfully. Some error occurred. Try Again. <a href='home.php?pages=viewRetailer'>Click to View</a>");			
			}
	}
}	
echo json_encode($arr);		    	
mysqli_close($cn);		
?>

