<?php
session_start();
ob_start();
include("config/database.php");
$conct  = new connectionCreat();
$conct->connectToDB();
$conct->selectDB();
include "config/function.php";
$take_action1   = new actionDo();
?>
<form action="" method="POST" enctype="multipart/form-data">
  <input type="file"  name="file" >
 <input type= "submit" name="upload" value ="Upload" >
</form>
<?php
if(isset($_SESSION['msg']))
{
	echo $_SESSION['msg'];
	unset($_SESSION['msg']);	
}
if(isset($_POST['upload']))
{
	$file   = $_FILES['file']['tmp_name'];
	$handle = fopen($file, "r");
	$i		= 0;$j		= 0;$k		= 0;
	while(($filesop = fgetcsv($handle, 1000, ",")) !== false)
	{
		if($i>0)
		{
			$sql_2 		= mysql_query(" select * from `tbl_emp_records` where `emp_name` ='".ucwords(strtolower(trim($filesop[3])))."' and `state`='".ucwords(strtolower(trim($filesop[0])))."' ")or die(mysql_error()); 
			if(mysql_num_rows($sql_2)>0)
			{
				$sql_2 	= mysql_query(" UPDATE `tbl_emp_records` SET  `account_no`='".$filesop[2]."',`emp_name`='".ucwords(strtolower(trim($filesop[3])))."',`branch_ifsc`='".$filesop[4]."',`bank_name`='".ucwords(strtolower(trim($filesop[5])))."' ,`payment_status`='Complete' where `emp_name` ='".$filesop[3]."' and `state`='".$filesop[0]."' ")or die(mysql_error()); 				
///				echo  "<br />";
				$j++;
			}
			else
			{
				echo "Employee Name : "	.$filesop[3]." ,State : ".$filesop[0];
				echo "<br />";
			}
	   }
	$i++;
	}
	if($i>0)
	{
		$_SESSION['msg'] = "Total Records Uploaded : ".($i-1)."<br />Total Matched : $j";
	}
	else
	{
		$_SESSION['msg'] = "Sorry! There is some problem.";
	}
	echo "<br />";
echo 	$_SESSION['msg'];die;
	header("location:update_payment_st.php");
}
 ?>