Jump to content
Larry Ullman's Book Forums

Issue With Ch. 11 - Pg 296 (Add_Quote.Php)


Recommended Posts

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.

 

permissions_zpsb9cb318d.png

 

 

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

 Share

×
×
  • Create New...