i have a problem when inserting data into a text file, the data gets repeated & doesn't create newlines. this is my code:
<?php
$id = trim(strip_tags($_GET['id']));
$myfile = fopen("../../asset/Timeline/Logline.txt", "a") or die("file tidak ditemukan");
$tgl=date('d/m/Y');
$jam=date('H:i:s');
$slnmdl="select nama from $tabname where ID='$id'";
$result = mysqli_query($conn, $slnmdl);
$row = mysqli_fetch_assoc($result);
$nmdl = $row['nama'];
$log_content="$tgl|$jam|menghapus data $nmdl \n";
fwrite($myfile, $log_content);
fclose($myfile);
?>
viewer.php
<?php
$file_handle = fopen("Timeline/Logline.txt", "rb");
while (!feof($file_handle) ) {
$line_of_text = fgets($file_handle);
$parts = explode('|', $line_of_text);
$lna=$parts[0];
$lnb=$parts[1];
$lnc=$parts[2];
echo "$lna $lnb $lnc <br>";
}
fclose($file_handle);
?>
output
12/08/2022 14:00:59 menghapus data eWF5YW5n
12/08/2022 14:00:59 menghapus data
Logline.txt
12/08/2022|14:00:59| menghapus data eWF5YW5n 12/08/2022|14:00:59| menghapus data
please help me find the fault