Advertisement
Guest User

Untitled

a guest
Apr 15th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. <?php
  2. $servername = "192.168.56.101";
  3. $username = "armando";
  4. $password = "qwerty123";
  5. $db = "demo_game_changer";
  6.  
  7. try {
  8.  
  9. $conn = new mysqli_connect($servername, $username, $password, $db);
  10. echo "Connected successfully";
  11. }
  12. catch(exception $e){
  13. {
  14. echo "Connection failed: " . $e->getMessage();
  15. }
  16. return $conn;
  17. }
  18.  
  19.  
  20. if(isset($_POST["Import"])){
  21.  
  22. $filename=$_FILES["file"]["tmp_name"];
  23.  
  24.  
  25. if($_FILES["file"]["size"] > 0)
  26. {
  27. $file = fopen($filename, "r");
  28. while (($getData = fgetcsv($file, 10000, ",")) !== FALSE)
  29. {
  30.  
  31. $sql = "INSERT into leads (domain,user_id,in_list,date_callback)
  32. values ('".$getData[0]."','0','0','2017-05-16')";
  33. $result = mysqli_query($conn, $sql);
  34. if(!isset($result))
  35. {
  36. echo "<script type=\"text/javascript\">
  37. alert(\"Invalid File:Please Upload CSV File.\");
  38. window.location = \"index.php\"
  39. </script>";
  40. }
  41. else {
  42. echo "<script type=\"text/javascript\">
  43. alert(\"CSV File has been successfully Imported.\");
  44. window.location = \"index.php\"
  45. </script>";
  46. }
  47. }
  48.  
  49. fclose($file);
  50. }
  51. }
  52. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement