Source Code PHP Import Data TXT to Database MySql
Berikut Adalah Source Code import data txt ke dalam mysql database.
<body>
<center><h1>lp2maray</h1></center>
<form name="import_export_form" method="post" enctype="multipart/form-data">
<label>Wilayah : </label><input type="text" name="wilayah"/><br>
<label>Select Pilih File : </label><input type="file" name="datatxt"/><br>
<br>
<input type="submit" name="form_submit"/>
</form>
</body>
Source Code HTML :
<body>
<center><h1>lp2maray</h1></center>
<form name="import_export_form" method="post" enctype="multipart/form-data">
<label>Wilayah : </label><input type="text" name="wilayah"/><br>
<label>Select Pilih File : </label><input type="file" name="datatxt"/><br>
<br>
<input type="submit" name="form_submit"/>
</form>
</body>
Source Code PHP :
<?php
if(isset($_POST['form_submit'])){
$wilayah=$_POST["wilayah"];
$filename = $_FILES['datatxt']['tmp_name'];
echo $filename;
$myfile = fopen($filename, "r") or die("Unable to open file!");
while(!feof($myfile)) {
$dataawal=fgets($myfile);
$data1 = explode(" ", $dataawal);
$d1 = $data1[0];
$d2 = $data1[1];
$d3 = $data1[2];
$d4 = $data1[3];
$d5 = $data1[4];
$d6 = $data1[5];
echo $sql=" INSERT INTO `$tbpasut` (
`wilayah` ,
`latitude` ,
`longitude` ,
`tanggal` ,
`jam` ,
`ketinggian` ,
`keterangan`
) VALUES (
'$wilayah',
'$d2',
'$d3',
'$d4',
'$d5',
'$d6',
'-'
)";
$simpan=process($conn,$sql);
if($simpan) {echo "<script>alert('Data $id_pasut berhasil disimpan !');document.location.href='?mnu=pasut';</script>";}
else{echo"<script>alert('Data $id_pasut gagal disimpan...');document.location.href='?mnu=pasut';</script>";}
}
fclose($myfile);
}
?>
if(isset($_POST['form_submit'])){
$wilayah=$_POST["wilayah"];
$filename = $_FILES['datatxt']['tmp_name'];
echo $filename;
$myfile = fopen($filename, "r") or die("Unable to open file!");
while(!feof($myfile)) {
$dataawal=fgets($myfile);
$data1 = explode(" ", $dataawal);
$d1 = $data1[0];
$d2 = $data1[1];
$d3 = $data1[2];
$d4 = $data1[3];
$d5 = $data1[4];
$d6 = $data1[5];
echo $sql=" INSERT INTO `$tbpasut` (
`wilayah` ,
`latitude` ,
`longitude` ,
`tanggal` ,
`jam` ,
`ketinggian` ,
`keterangan`
) VALUES (
'$wilayah',
'$d2',
'$d3',
'$d4',
'$d5',
'$d6',
'-'
)";
$simpan=process($conn,$sql);
if($simpan) {echo "<script>alert('Data $id_pasut berhasil disimpan !');document.location.href='?mnu=pasut';</script>";}
else{echo"<script>alert('Data $id_pasut gagal disimpan...');document.location.href='?mnu=pasut';</script>";}
}
fclose($myfile);
}
?>
Selamat mencoba, semoga bermanfaat ya...... Terimakasih
Nggaada Noda Ngga Belajar
Posting Komentar untuk "Source Code PHP Import Data TXT to Database MySql"