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

