<?php 
ob_start();
session_start();
require_once("../conn/conn.php");
@include('../utility/chksession.php');

$id_po=$_REQUEST['id_po'];

echo $id_po;

//exit;

if (isset($_POST["import"])) {
    
	
    $fileName = $_FILES["file"]["tmp_name"];
    
    if ($_FILES["file"]["size"] > 0) {
        
        $file = fopen($fileName, "r");
        
        while (($column = fgetcsv($file, 10000, ",")) !== FALSE) {
			
            $sqlInsert = "INSERT into pd_posub2 (id_po,id_item,part_qty,id_dep )
                   			values ('$id_po','" . $column[0] . "','" . $column[1] . "','" . $column[2] . "','" . $column[3] . "')";
           
			$result = mysqli_query($con,$sqlInsert);
            
          echo $column[1].$column[2];
            
        }
	exit;
		 if ($result) {
                //$type = "success";
                //$message = "CSV Data Imported into the Database";
				//echo $type;
				?>
				<script language="javascript" type="text/javascript">
				alert("เพิ่มข้อมุลเรียบร้อยแล้ว");
				location="data_posub.php?id_po=51";
				</script>
			<?php
            } else {
                //$type = "error";
                //$message = "Problem in Importing CSV Data";
				?>
				<script language="javascript" type="text/javascript">
				alert("ไม่สามารถเพิ่มข้อมูลได้ !!!");
				location="data_posub.php?id_po=51";
				</script>
			<?php
			} 
    }

	
}
?>

</body>
</html>