How can PHP be used to update a .txt file based on user input from a form without using a database?
To update a .txt file based on user input from a form without using a database, you can read the content of the file, modify it according to the user input, and then write the updated content back to the file.
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$user_input = $_POST["user_input"];
$file_path = "data.txt";
$content = file_get_contents($file_path);
// Update the content based on user input
$updated_content = $content . "\n" . $user_input;
file_put_contents($file_path, $updated_content);
echo "File updated successfully!";
}
?>