Guest User

Untitled

a guest
Mar 14th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
  4. </head>
  5.  
  6. <body>
  7. <form name="import" method="post" enctype="multipart/form-data">
  8. કેમ છે: <input type="file" name="file" /><br />
  9. <input type="submit" name="submit" value="Submit" />
  10. </form>
  11. <?php
  12. include ("connection.php");
  13.  
  14. if(isset($_POST["submit"]))
  15. {
  16. $file = $_FILES['file']['name'];
  17. $handle = fopen($file, "r");
  18. $c = 0;
  19. while(($filesop = fgetcsv($handle, 1000, ",")) !== false)
  20. {
  21. $name = $filesop[0];
  22. $marks = $filesop[1];
  23. mysql_query("set name utf8");
  24. $query = "INSERT INTO temp (name, marks) VALUES ('".$name."','".$marks."')";
  25. echo $query;
  26. $sql = mysql_query($query);
  27. }
  28. }
  29. ?>
  30.  
  31. </div>
  32. </body>
  33. </html>
  34.  
  35. <?php
  36.  
  37. $hostname = "localhost";
  38. $username = "root";
  39. $password = "";
  40. $database = "test";
  41. $conn = mysql_connect("$hostname","$username","$password") or die(mysql_error());
  42. mysql_select_db("$database", $conn) or die(mysql_error());
  43.  
  44. ?>
  45.  
  46. function convToUtf8($str){
  47. if( mb_detect_encoding($str,"UTF-8, ISO-8859-1, GBK")!="UTF-8" )
  48. return iconv("gbk","utf-8",$str);
  49. else
  50. return $str;
  51. }
  52.  
  53. while(($filesop = fgetcsv($handle, 1000, ",")) !== false)
  54. {
  55. $name = convToUtf8($filesop[0]);
  56. $marks = convToUtf8($filesop[1]);
  57. //mysql_query("set name utf8"); No need to do this now
  58. $query = "INSERT INTO temp (name, marks) VALUES ('$name','$marks')";
  59. echo $query;
  60. $sql = mysql_query($query);
  61. }
Add Comment
Please, Sign In to add comment