How can PHP be used to write input from a form into a text file and add new input to existing data?
To write input from a form into a text file and add new input to existing data in PHP, you can use the file_put_contents function with the FILE_APPEND flag. This function will write data to a file, creating the file if it doesn't exist, and appending new data to the existing content. You can retrieve the form input using the $_POST superglobal and then use file_put_contents to write the data to a text file.
<?php
// Retrieve form input
$input = $_POST['input'];
// Write input to text file
file_put_contents('data.txt', $input . PHP_EOL, FILE_APPEND);
?>