<?session_start();
include("../opendb.php");

//print sizeof($a);

if($upd)
 {
if($ff !="none")
{
   $fl=$HTTP_POST_FILES['ff']['name'];
   $file_dir=".";
  $tmp_name=$_FILES['ff']['tmp_name'];

   move_uploaded_file($tmp_name,"./$file_dir/$ff_name") or die(' err:could not copy file');
  print "File copied :".$fl;
 }
$fp=fopen("./$file_dir/$ff_name","r") or die("Cant open file");
$i=1;
include("opendb.php");
mysqli_query($db,"delete from amcparts where brcode='$brcode'");
$dt=date("Y-m-d H:i:s");
$i=1;
while(!feof($fp))
{
 $line=fgets($fp,1024);
 $spline=explode("\t",$line);
if(strlen($spline[1])>0)
{

$sql="insert into amcparts values('$spline[0]','".addslashes(trim($spline[1]))."','$spline[2]', '".addslashes(trim($spline[3]))."','".addslashes($spline[4])."','$spline[5]','$spline[6]','$spline[7]','$spline[8]','$spline[9]','$spline[10]', '$spline[11]','$spline[12]','$spline[13]','$brcode','$user','".$dt."',".$i++.")";
//print $i++.". ".$sql."<br>";
mysqli_query($db,$sql) or die('Insert Err:'.mysqli_error());
}
//$re=mysqli_query($db,"select * from amcmast where chasisno='$no'");
//if(mysqli_num_rows($re)<=0)
// {
  //  print "amc does not exist";
 //   return;
// }
}
print "<script> alert('Done');</script>";
}

?>

<link rel="stylesheet" href="style.css" type="text/css" />
<style>
body,td{font-family:'arial narrow';letter-spacing:1;}
tr{background-color:c1d799}
.mnu{margin-left:5}
</style>
<center>
<br><br><br><br><br><br>
<form action='<?print $PHP_SELF?>' method='post' ENCTYPE="multipart/form-data">
<table border=1>
<tr><td>
<table>
<th colspan=2>Upload Daily Stock
<tr><td>File </td><td><input type=file name='ff'></td></tr>
<tr><td><input type=submit value='Upload' name='upd'></td></tr>
</table>
</td></tr>
</table>
</form>
