Postingan lainnya
Kelas Premium!
Belajar bikin website dari nol sekarang
Gunakan kupon "lebihcepat" untuk diskon 25%!
Export txt dengan batasan waktu
Halo Master,
Mau tanya dong apa ada yg salah dengan script saya ya? <a href='https://drive.google.com/file/d/1RcpG70OodRzAhkUGLfiaxAlhZQ-bECfM/view'>Export File ScreenShot</a> Ini file index.php nya
<form method="POST" action="export3.php">
<div class="modal-sm">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Print Filter ?
</h4>
</div>
<div class="modal-body">
<div class="control-group">
<label class="col-sm-2 control-label">Start Date</label>
<div class="col-sm-6">
<input type="datetime-local" name="from" id="stayf" class="form-control" style="width:515px;height:25px">
</div>
</div>
<div class="control-group">
<label class="col-sm-2 control-label">End Date</label>
<div class="col-sm-8">
<input type="datetime-local" name="end" id="stayf" class="span5" style="width:515px;height:25px">
</div>
</div>
</div>
<div class="modal-footer">
<button data-dismiss="modal" class="btn btn-default" type="button">Cancel
</button>
<button class="btn btn-info" type="submit" name="submit" value="export" onclick="return valid();">EXPORT FILE
</button>
</div>
</div>
</div>
</form>
Ini file export.php
<?php
if(isset($_POST["export"])) {
// nama file hasil export
$namaFile = "data.txt";
// koneksi ke mysql
$dbname = "logabsensi";
$dbuser = "dewean";
$dbpass = "53cur1ty";
$dbhost = "localhost";
mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname);
// header file text
header("Content-type: text/plain");
header("Content-Disposition: attachment; filename=".$namaFile);
// query sql baca semua data dalam tabel
$query = "SELECT * FROM punchlog where bsevtdt>= '".$_POST["from"]."' AND bsevtdt<= '".$_POST["end"]."'";
$hasil = mysql_query($query);
while ($data = mysql_fetch_array($hasil))
{
echo "31";
$date=date_create($data["bevtdt"]);
echo date_format($date,"Ymd");
echo date_format($date,"Hi");
echo "000";
echo "$data[tk]";
echo "000";
echo "$data[user_id]";
echo "0001\n";
}
fclose($output);
}
?>
2 Jawaban:
itu php5 kebawah kah? atau emang pakai php7 coba cek version nya, kalo pake php7 ganti mysql ke mysqli buat connect ke databse nya https://www.php.net/manual/en/function.mysqli-connect.php
jarang sekarang yang masih pake php5, tapi masih banyak tutor indo yang masih pake mysql
Iya masih pake php5, belum update lagi soalnya PHP nya, hehehe tapi makasih loh. Akhirnya udah bisa skrg.