Guest User

Untitled

a guest
Feb 1st, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. <?php
  2. if(isset($_POST["Import"]))
  3. {
  4. //First we need to make a connection with the database
  5. $host='localhost'; // Host Name.
  6. $db_user= 'root'; //User Name
  7. $db_password= '';
  8. $db= 'testdatabase'; // Database Name.
  9. $conn=mysql_connect($host,$db_user,$db_password) or die (mysql_error());
  10. mysql_select_db($db) or die (mysql_error());
  11. echo $filename=$_FILES["file"]["tmp_name"];
  12. if($_FILES["file"]["size"] > 0)
  13. {
  14. $file = fopen($filename, "r");
  15. $count = 0;
  16. $sql_data = "SELECT * FROM person";
  17. echo $sql_data;
  18. while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE)
  19. {
  20. //print_r($emapData);
  21. //exit();
  22. $count++;
  23. if($count > 1) {
  24. $sql = "INSERT into person(firstname , lastname) values ('$emapData[0]','$emapData[1]')";
  25. mysql_query($sql);
  26. echo "success";
  27.  
  28. }
  29. }
  30. fclose($file);
  31. echo 'CSV File has been successfully Imported';
  32. header('Location: index.php');
  33. }
  34. else
  35. echo 'Invalid File:Please Upload CSV File';
  36. }
  37. ?>
Add Comment
Please, Sign In to add comment