Guest User

Untitled

a guest
Oct 31st, 2018
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. <form class="ui input" enctype="multipart/form-data" method = "POST" role = "form">
  2. <input type = "file" name ="file" id="file" size = "150">
  3. <button class="ui small red button" type = "submit" class = "btn btn-default" name ="submit" value = "submit">Upload CSV</button>
  4. </form>
  5.  
  6. <?php
  7.  
  8. if(isset($_POST['submit'])) {
  9. $host = 'localhost';
  10. $user = 'root';
  11. $password = '';
  12. $db = 'jeremy_db';
  13.  
  14. $con = mysqli_connect($host,$user,$password) or die('Could not' .mysqli_error($con));
  15.  
  16. mysqli_select_db($con, $db) or die ('Could not' .mysqli_error($con));
  17.  
  18. $file = $_FILES['file']['tmp_name'];
  19. $handle = fopen($file, "r");
  20.  
  21. $c = 0;
  22.  
  23. while(($csvdata = fgetcsv($handle,1000,","))!== FALSE){
  24. $sha1 = $csvdata[0];
  25. $vsdt = $csvdata[1];
  26. $trendx = $csvdata[2];
  27.  
  28. $sql = "INSERT INTO jeremy_table_trend (sha1,vsdt,trendx) VALUES ('$sha1','$vsdt','$trendx')";
  29. $query = mysqli_query($con , $sql);
  30.  
  31. $c = $c+1;
  32. }
  33. if($query){
  34. echo "SABRE";
  35. }
  36. else {
  37. echo "SLAM";
  38. }
  39. }
  40. ?>
Add Comment
Please, Sign In to add comment