Sanady

Untitled

May 12th, 2019
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. <?php
  2. include_once ("config.php");
  3.  
  4. $conn = new mysqli($servername, $username, $password, $dbname);
  5.  
  6. if($conn->connect_error){
  7. die("Connection failed: " . $conn->connect_error);
  8. }
  9.  
  10. if(isset($_POST["Import"])){
  11.  
  12. $filename=$_FILES["file"]["tmp_name"];
  13.  
  14. if($_FILES["file"]["size"] > 0)
  15. {
  16. $file = fopen($filename, "r");
  17. while (($getData = fgetcsv($file, 10000, ",")) !== FALSE)
  18. {
  19. $sql = "INSERT INTO `users` (`id`, `meno`, `email`, `heslo`, `team`, `role`, `accept`, `points`) VALUES
  20. ('$getData[0]','".$getData[1]."','".$getData[2]."','".$getData[3]."','".$getData[4]."','".$getData[5]."','".$getData[6]."','".$getData[7]."')";
  21. //result = mysqli_query($con, $sql);
  22. echo $sql;
  23. $result = $conn->query($sql);
  24. if(!isset($result))
  25. {
  26. echo "<script type=\"text/javascript\">
  27. alert(\"Invalid File:Please Upload CSV File.\");
  28. window.location = \"index.php\"
  29. </script>";
  30. }
  31. else {
  32. echo "<script type=\"text/javascript\">
  33. alert(\"CSV File has been successfully Imported.\");
  34. window.location = \"index.php\"
  35. </script>";
  36. }
  37. }
  38.  
  39. fclose($file);
  40. //var_dump($getData);
  41. }
  42. }
  43.  
  44. ?>
Advertisement
Add Comment
Please, Sign In to add comment