0

Hi,I am uploading CSV file.its working fine.
but an extra record(blank record) added with all csv records
Need help for above

<?php session_start();
if (!isset($_SESSION['username']))
{
header('Location: login.php');
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<style type="text/css">
table, th
{
border:1px solid #666666;
font-family:Verdana;
font-size:12px;
vertical-align:top;
}
th
{
background-color:#666666;
color:white;
}
</style>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>

<body>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" enctype="multipart/form-data" method="post">
<table align="center" width="600px">
<tr>
<td align="right">Welcome :<?php echo $_SESSION['username']; ?>&nbsp;&nbsp;<a href="logout.php" >Logout</a></td>
</tr>
<tr>
<td><strong>Select file:</strong><input type="file" name="uploadedfile"/></td></tr>
<tr><td align="center" style="padding-right:50px"><input type="submit" name="submit" value="Upload records"/></td>
</tr>
</table>
</form>
</body>
</html>
<?php   
            include('db_hindi.php');
            echo $filename = $_FILES['uploadedfile']['name'];
            $filepath = "upload/";
			$uniq1=@uniqid($uniq1);
			$filename=$uniq1.$filename;
			$source = $_FILES['uploadedfile']['tmp_name'];
			$target = $filepath.$filename;
			if(move_uploaded_file($source, $target))
			{
				$i=0;
				$handle = fopen($target, "r");
								while (($data = fgetcsv($handle, 3000, ",")) !== FALSE)
				{
					if($i!=0)
					{
							$import="INSERT into tbl_hindi(num,address,name,father,state,city,gender,mobile,dob,namdan_date,file,mobile1,english_name,abbr) values('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]','$data[5]','$data[6]','$data[7]','$data[8]','$data[9]','$data[10]','$data[11]','$data[12]','$data[13]')";
												
					$rs_import=mysql_query($import);
						if(!$rs_import)
							 $msg="Upload Failed!";
						else
						  $msg="File has been uploaded successfully!";
					}
					$i++;
				}
				fclose($handle);
			}
			else
			{
				 $msg="Upload Failed!";
			}
			?>
2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by karthik_ppts
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.