Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <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>
- <?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());
- ?>
- function convToUtf8($str){
- if( mb_detect_encoding($str,"UTF-8, ISO-8859-1, GBK")!="UTF-8" )
- return iconv("gbk","utf-8",$str);
- else
- return $str;
- }
- while(($filesop = fgetcsv($handle, 1000, ",")) !== false)
- {
- $name = convToUtf8($filesop[0]);
- $marks = convToUtf8($filesop[1]);
- //mysql_query("set name utf8"); No need to do this now
- $query = "INSERT INTO temp (name, marks) VALUES ('$name','$marks')";
- echo $query;
- $sql = mysql_query($query);
- }
Add Comment
Please, Sign In to add comment