DanielHardy Posted August 9, 2009 Share Posted August 9, 2009 Hi all, I have a simple guestbook code that writes to and reads froma txt file. It reads from the file ok but will not add to it. Here is the code <?php // Save filename to variable. $guestbook = "messages.txt"; // This will run if someone sends user input. if (isset($_POST['button'])) { // Check whether any fields are empty or not. if (!empty($_POST['name']) && !empty($_POST['message'])) { // Bad characters in E-Mail string. $badSearch = array("@", "."); // Goods characters in E-Mail string. $goodSearch = array(" @ ", " . "); // Grab name from the form and add a newline afterwards. $string .= "<b>" . $_POST['name'] . " "; // Grab email and replace the @ and . in the string. $string .= str_replace($badSearch, $goodSearch, $_POST['email']) . "</b>\n"; // Grab the message and save it in $string. $string .= "<font color=#2766c5>" . $_POST['message'] . "</font>\n<hr>"; // Open messages.txt and append more posts to it. $file = fopen($guestbook, "a"); // Write $string to the text file and replace bad characters to avoid XSS attacks. fwrite($file, nl2br(strip_tags($string, "<b><hr><font>"))); // Close the file we opened. fclose($file); echo '<script>alert("Your comment has been added ")</script>'; } else { // Of the form fields are empty will there popup a message. echo '<script>alert("Please fill out the whole form")</script>'; } } $readfile = fopen($guestbook, "r"); echo @fread($readfile, filesize($guestbook)); fclose($readfile); ?> Any help is greatly appreciated. Thanks Dan Link to comment https://forums.phpfreaks.com/topic/169462-can-anyone-tell-me-why-this-isnt-working/ Share on other sites More sharing options...
papaface Posted August 9, 2009 Share Posted August 9, 2009 Put this at the top of your file and then tell us the output: error_reporting(E_ALL); ini_set('display_errors', '1'); Link to comment https://forums.phpfreaks.com/topic/169462-can-anyone-tell-me-why-this-isnt-working/#findComment-894079 Share on other sites More sharing options...
DanielHardy Posted August 11, 2009 Author Share Posted August 11, 2009 Very weird. I have discovered it works in Firefox but not I.E. Any ideas? Link to comment https://forums.phpfreaks.com/topic/169462-can-anyone-tell-me-why-this-isnt-working/#findComment-895247 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.