Getting below error:
Warning: fopen(detail.csv) [function.fopen]: failed to open stream: No such file or directory in C:\xampp\htdocs\hindi\import_file.php on line 28

Warning: fgetcsv() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\hindi\import_file.php on line 29
Column count doesn't match value count at row 1


Need suggestions

<!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>
<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">
<strong>Import file:</strong><input type="file" name="uploadedfile"/>
<input type="submit" name="submit" value="submit"/>
</form>
</body>
</html>
<?php
if(isset($_POST['submit']))
{
include('db_hindi.php');
$file = $_FILES['uploadedfile']['name'];
$target_path="upload/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path);
$chk_ext = explode(".",$file);
if(strtolower($chk_ext[1]) == "csv")
     {
     $filename = $_FILES['uploadedfile']['tmp_name'];
     $handle = fopen($file, "r");
     while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
      { 
       $sql = "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]','$data[14]','$data[15]')";
       mysql_query($sql) or die(mysql_error());
      }
      fclose($handle);
      echo "Successfully Imported";
     }
     
	     else
	     {
	         echo "Invalid File";
	     }    
	    

		
}

?>

only 14 columns available but u put 16 values in query...

try this

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

only 14 columns available but u put 16 values in query...

sorry,i forget to edit..
still m getting error
Warning: fopen(detail.csv) [function.fopen]: failed to open stream: No such file or directory in C:\xampp\htdocs\hindi\import_file.php on line 28

Warning: fgetcsv() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\hindi\import_file.php on line 29

Warning: fgetcsv() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\hindi\import_file.php on line 29

Warning: fgetcsv() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\hindi\import_file.php on line 29

Warning: fgetcsv() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\hindi\import_file.php on line 29

Warning: fgetcsv() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\hindi\import_file.php on line 29

Warning: fgetcsv() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\hindi\import_file.php on line 29

Warning: fgetcsv() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\hindi\import_file.php on line 29

try with my code

Replace your line 28 with

$handle = fopen($target_path, "r");

Replace your line 28 with

$handle = fopen($target_path, "r");

I am not getting any value from csv file.

Warning: fgetcsv() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\hindi\import_file.php on line 27
INSERT into tbl_hindi(num,address,name,father,state,city,gender,mobile,dob,namdan_date,file,mobile1,english_name,abbr) values('','','','','','','','','','','','','','')
Warning: fgetcsv() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\hindi\import_file.php on line 27
INSERT into tbl_hindi(num,address,name,father,state,city,gender,mobile,dob,namdan_date,file,mobile1,english_name,abbr) values('','','','','','','','','','','','','','')
Warning: fgetcsv() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\hindi\import_file.php on line 27
INSERT into tbl_hindi(num,address,name,father,state,city,gender,mobile,dob,namdan_date,file,mobile1,english_name,abbr) values('','','','','','','','','','','','','','')

Still getting error.

Do you have file in your target path?

Do you have file in your target path?

It is not stored as same file which i am uploading.
I uploaded detail.csv but it save as a 4e1190a12e987.file

which code you used? your code or my code?

which code you used? your code or my code?

I am Using your code.

<!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>
<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">
<strong>Import file:</strong><input type="file" name="uploadedfile"/>
<input type="submit" name="submit" value="submit"/>
</form>
</body>
</html>
<?php   
            include('db_hindi.php');
            $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_path, "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!";
			}
			?>

Add this line

$filename = $_FILES['uploadedfile']['name'];

before your 20th line.

Replace the line 26

$handle = fopen($target_path, "r");

with

$handle = fopen($target, "r");

still getting error,
detail.csv stored as a 4e119d7888721detail

Warning: fgetcsv() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\hindi\import_file.php on line 28

Warning: fgetcsv() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\hindi\import_file.php on line 28

Warning: fgetcsv() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\hindi\import_file.php on line 28

Warning: fgetcsv() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\hindi\import_file.php on line 28

Warning: fgetcsv() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\hindi\import_file.php on line 28

Warning: fgetcsv() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\hindi\import_file.php on line 28

Add this line

$filename = $_FILES['uploadedfile']['name'];

before your 20th line.

Replace the line 26

$handle = fopen($target_path, "r");

with

$handle = fopen($target, "r");

post your full current code here...

<!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>
<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">
<strong>Import file:</strong><input type="file" name="uploadedfile"/>
<input type="submit" name="submit" value="submit"/>
</form>
</body>
</html>
<?php   
            include('db_hindi.php');
            $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_path, "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!";
			}
			?>

post your full current code here...

replace your line 27

$handle = fopen($target_path, "r");

with

$handle = fopen($target, "r");
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.