
<?php

if(isset($_POST["submit"]))
{
	
	
$db_host="127.0.0.1:3306";    //host name
$db_login="auminfosys";         //user name
$db_pass="Hemen@aum111control";       //password
$db_base="auminfosyserp";     //database name

$connection = mysql_connect($db_host, $db_login, $db_pass) or die ("Unable to connect!" . "<br /> Error :"  . mysql_error());
mysql_select_db($db_base) or die ("Unable to select database!" . "<br /> Error :"  . mysql_error());
 
 
 $filename=$_FILES["file"]["name"]; 
$ext=substr($filename,strrpos($filename,"."),(strlen($filename)-strrpos($filename,".")));

function convToUtf8($str){ 
    if( mb_detect_encoding($str,"UTF-8, ISO-8859-1, GBK")!="UTF-8" ) 
        return  iconv("gbk","utf-8",$str);
    else
        return $str; 
}

//we check,file must be have csv extention
if($ext==".csv")
{
  $file = fopen($filename, "r");

         while (($emapData = fgetcsv($file, 10000000, ",")) !== FALSE)
         {
		
	
            $sql = "INSERT into csc_customer(
			sr_no,
			company_name,
			csc_id,
			estore_name,
			vendor_name,
			estore_phoneno,
			alternate_number,
			document_type,
			document_no,
			vendor_email,
			distributor_name,
			distributor_phoneno,
			order_no,
			address,
			district,
			state,
			gst_no,
			product_name,
			sku,
			quantity,
			mrp,
			payment_date,
			payment_mode,
			order_status,
			order_date,
			transcation_id,
			gatway_id,
			transcation_date,
			transcation_status,
			master_distribution
			) 
			values('$emapData[0]','$emapData[1]','$emapData[2]','$emapData[3]','$emapData[4]','$emapData[5]','$emapData[6]','$emapData[7]'
			,'$emapData[8]','$emapData[9]','$emapData[10]','$emapData[11]','$emapData[12]','$emapData[13]','$emapData[14]'
			,'$emapData[15]','$emapData[16]','$emapData[17]','$emapData[18]','$emapData[19]','$emapData[20]','$emapData[21]','$emapData[22]','$emapData[23]','$emapData[24]','$emapData[25]','$emapData[26]','$emapData[27]','$emapData[28]','$emapData[29]')";
			echo $sql1; exit;
		   dbQuery($sql);
			
			
	
			
		
         }
         fclose($file);
         echo "CSV File has been successfully Imported.";
}
else {
    echo "Error: Please Upload only CSV File";
}
 
 
}
?>
