What potential issues could arise from using a text file to store guestbook entries in PHP?

One potential issue that could arise from using a text file to store guestbook entries in PHP is the lack of data validation, which could lead to security vulnerabilities such as SQL injection attacks. To solve this, you should sanitize and validate user input before writing it to the text file.

// Sanitize and validate user input before writing to the text file
$guestbookEntry = filter_var($_POST['guestbook_entry'], FILTER_SANITIZE_STRING);

// Write the sanitized entry to the text file
$file = 'guestbook.txt';
$currentEntries = file_get_contents($file);
$currentEntries .= $guestbookEntry . PHP_EOL;
file_put_contents($file, $currentEntries);