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
My Answer:
This issue could be caused by the way you are writing the data to the text file. Make sure that you are not accidentally appending the data multiple times or writing it in a loop that runs more than once.
You can also check if the data you are trying to write is being duplicated before it is written to the file. Make sure that you are only writing the data once and that there are no duplicate entries in the input data.
If you are still facing the issue, you can try clearing the contents of the text file before writing the new data to it. This can help prevent any existing data from being duplicated.
If none of these solutions work, you may need to provide more information or code snippets for further assistance.
Rate this post
5 of 5 based on 4532 votesComments