Guest User

Untitled

a guest
Jan 31st, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. <form enctype="multipart/form-data" method="post" action="import.php" role="form">
  2. <div class="form-group">
  3. <label for="exampleInputFile">File Upload</label>
  4. <input type="file" name="file" id="file" size="150">
  5. <p class="help-block">Only Excel/CSV File Import.</p>
  6. </div>
  7. <button type="submit" class="btn btn-default" name="Import" value="Import">Upload</button>
  8. </form>
  9.  
  10. [![<?php
  11. if(isset($_POST["Import"]))
  12. {
  13. //First we need to make a connection with the database
  14. $host='localhost'; // Host Name.
  15. $db_user= 'root'; //User Name
  16. $db_password= '';
  17. $db= 'testdatabase'; // Database Name.
  18. $conn=mysql_connect($host,$db_user,$db_password) or die (mysql_error());
  19. mysql_select_db($db) or die (mysql_error());
  20. echo $filename=$_FILES["file"]["tmp_name"];
  21. if($_FILES["file"]["size"] > 0)
  22. {
  23. $file = fopen($filename, "r");
  24. $count = 0;
  25. $sql_data = "SELECT * FROM person";
  26. echo $sql_data;
  27. console.log("tst:" , $sqldata);
  28. while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE)
  29. {
  30. //print_r($emapData);
  31. //exit();
  32. $count++;
  33. if($count > 1) {
  34. $sql = "INSERT into person(firstname , lastname) values ('$emapData[0]','$emapData[1]')";
  35. mysql_query($sql);
  36. echo "success";
  37.  
  38. }
  39. }
  40. fclose($file);
  41. echo 'CSV File has been successfully Imported';
  42. header('Location: index.php');
  43. }
  44. else
  45. echo 'Invalid File:Please Upload CSV File';
  46. }
  47. ?>][1]][1]
Add Comment
Please, Sign In to add comment