Following code which is used to browse csv file. Fatch data from csv and store in a MySQL database.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
</head>
<body>
<form name="import" method="post" enctype="multipart/form-data">
કેમ છે: <input type="file" name="file" /><br />
<input type="submit" name="submit" value="Submit" />
</form>
<?php
include ("connection.php");
if(isset($_POST["submit"]))
{
$file = $_FILES['file']['name'];
$handle = fopen($file, "r");
$c = 0;
while(($filesop = fgetcsv($handle, 1000, ",")) !== false)
{
$name = $filesop[0];
$marks = $filesop[1];
mysql_query("set name utf8");
$query = "INSERT INTO temp (name, marks) VALUES ('".$name."','".$marks."')";
echo $query;
$sql = mysql_query($query);
}
}
?>
</div>
</body>
</html>
Following code is used connect database.
<?php
$hostname = "localhost";
$username = "root";
$password = "";
$database = "test";
$conn = mysql_connect("$hostname","$username","$password") or die(mysql_error());
mysql_select_db("$database", $conn) or die(mysql_error());
?>
When I run code its stored data like "????????".
My CSV file like below
Following phpmyadmin version information
Following is my table structure