phpstuff Posted June 25, 2013 Share Posted June 25, 2013 Mac OSX 10.6.4 Firefox 21.0 PROBLEM - I keep getting error message. I think the code is correct, but maybe the permissions for the txt file are not?? I included screen shots of the error, the permissions settings, and the code below. Here is my code: <!DOCTYPE HTML><html><head><title>Add a Quotation</title></head><body><?php //Script 11.1 - add_quote.php//This script handles and displays an HTML form, and takes text input and stores it in a text file.//First identify the file to use:$file = '../quotes.txt';//Check for a form submission:if ($_SERVER['REQUEST_METHOD'] == 'POST') { //handle the form if ( !empty($_POST['quote']) && ($_POST['quote'] != 'Enter your quotation here.') ) { //Need something to write. if (is_writable($file)) { //Confirm the file is writable file_put_contents($file, $_POST['quote'] . PHP_EOL, FILE_APPEND); //write the data //Print a message: print '<p>Your quotation has been stored.</p>'; } else { // Could not open the file. print '<p style="color: red;">Your quotation could not be stored due to a system error.</p>'; } } else { // Failed to enter a quotation. print '<p style="color: red;">Please enter a quotation!</p>'; } } // End of submitted IF. //Leave PHP and display the form: ?> <form action="add_quote.php" method="post"> <textarea name="quote" rows="5" cols="30">Enter your quotation here.</textarea><br /> <input type="submit" name="submit" value="Add this quote!" /> </form> </body></html> Link to comment Share on other sites More sharing options...
phpstuff Posted June 25, 2013 Author Share Posted June 25, 2013 Jeez... nevermind... made a noobie mistake and didn't put the txt file in a seperate directory... I moved the php file to its own folder and it fixed everything... Link to comment Share on other sites More sharing options...
Larry Posted June 26, 2013 Share Posted June 26, 2013 Excellent. Kudos for figuring it out and thanks for sharing the solution. Also, in the future, please include the actual error message that you see. Link to comment Share on other sites More sharing options...
Recommended Posts