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!";
			}
			?>

is the input csv file fine?

is the input csv file fine?

Hi this is my attachement

where is your attachment?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.