First read in the old contents of the file, append your new messages to each line, and write that out.
$log_file_name="mylog.html"; // Change to the log file name
$message1 = "'" . $_POST['message1']."'<BR>"; // incoming message
$message2 = "'" . $_POST['message2']."'<BR>"; // incoming message
$message3 = "'" . $_POST['message3']."'<BR>"; // incoming message
$old = file_get_contents($log_file_name);
$lines = explode('<BR>', $old);
$lines[0] .= $message1;
$lines[1] .= $message2;
$lines[2] .= $message3;
unset($lines[3]); // Get rid of extra <BR>
file_put_contents($log_file_name, implode('', $lines));
If you have lots of POST messages, it would probably be better to make them an array. The form should use:
<input type="text" name="message[]">
for all the message inputs. Then you can use a foreach
loop to process them.
$log_file_name="mylog.html"; // Change to the log file name
$old = file_get_contents($log_file_name);
$lines = explode('<BR>', $old);
foreach ($_POST['message'] as $i => $message) {
$lines[$i] .= "'$message'<BR>";
}
unset($lines[count[$lines]-1); // Get rid of extra <BR>
file_put_contents($log_file_name, implode('', $lines));
12
solved Insert text using php on webserver