Advertisement
Guest User

excel

a guest
Sep 6th, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. <?php
  2. $hostname ="localhost";
  3. $username = "root";
  4. $password = "root";
  5. $database = "excel";
  6. $conn = mysqli_connect("$hostname","$username","$password","$database") or die(mysql_error());
  7. ?>
  8. <html>
  9. <head>
  10. </head>
  11. <body>
  12.  
  13. <div style="text-align:left; border:1px solid #333333; width:300px; margin:0 auto; padding:10px;">
  14.  
  15. <form name="import" method="post" enctype="multipart/form-data">
  16. <input type="file" name="file" /><br />
  17. <input type="submit" name="submit" value="Submit" />
  18. </form>
  19. <?php
  20. if(isset($_POST["submit"]))
  21. {
  22. $file = $_FILES['file']['tmp_name'];
  23. $handle = fopen($file, "r");
  24. $c = 0;
  25. while(($filesop = fgetcsv($handle, 1000, ",")) !== false)
  26. {
  27. $name = $filesop[0];
  28. $project = $filesop[1];
  29. $harga = $filesop[2];
  30.  
  31. $sql = mysqli_query($conn,"INSERT INTO tb_data (nama, alamat,harga) VALUES ('$name','$project','$harga')");
  32. $c = $c + 1;
  33. }
  34.  
  35. if($sql){
  36. echo "successfully. You have inserted ". $c ." recoreds";
  37. }else{
  38. echo "Sorry! There is some problem.";
  39. }
  40.  
  41. }
  42. ?>
  43. </div>
  44. </body>
  45. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement