Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $hostname ="localhost";
- $username = "root";
- $password = "root";
- $database = "excel";
- $conn = mysqli_connect("$hostname","$username","$password","$database") or die(mysql_error());
- ?>
- <html>
- <head>
- </head>
- <body>
- <div style="text-align:left; border:1px solid #333333; width:300px; margin:0 auto; padding:10px;">
- <form name="import" method="post" enctype="multipart/form-data">
- <input type="file" name="file" /><br />
- <input type="submit" name="submit" value="Submit" />
- </form>
- <?php
- if(isset($_POST["submit"]))
- {
- $file = $_FILES['file']['tmp_name'];
- $handle = fopen($file, "r");
- $c = 0;
- while(($filesop = fgetcsv($handle, 1000, ",")) !== false)
- {
- $name = $filesop[0];
- $project = $filesop[1];
- $harga = $filesop[2];
- $sql = mysqli_query($conn,"INSERT INTO tb_data (nama, alamat,harga) VALUES ('$name','$project','$harga')");
- $c = $c + 1;
- }
- if($sql){
- echo "successfully. You have inserted ". $c ." recoreds";
- }else{
- echo "Sorry! There is some problem.";
- }
- }
- ?>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement