Jump to content
Larry Ullman's Book Forums

Recommended Posts

i'm working on Ch.11 on a windows 7 with php 5.3...after downloading xampp. i put the text file: quotes.txt in the web root directory. (Is this the same area where htdocs is located?) after finishing add_quote.php and uploading it to my browser, i'm getting an error that reads: "Your quotation could not be stored due to a system error." So, i guess i'm not able to send my quote to the quote.txt file. Is it my file permissions or is it my file location that is the problem? I didn't do anything to the file permissions because the book is a bit hazy as to how windows users should deal with this. If there are any suggestions as to how i can resolve this, I'd appreciate it.

Link to comment
Share on other sites

<body>

<p>

<?php // Script 11.1 - add_quote.php

$file = '../quotes.text';

 

if ($_SERVER['REQUEST_METHOD'] == 'POST'){

 

if ( !empty($_POST['quote']) && ($_POST['quote'] != 'Enter your quotation here!.') ){

 

if (is_writable($file)){

// script 11.2 modified with LOCK_EX added:

file_put_contents($file, $_POST['quote'] . PHP_EOL, FILE_APEND | LOCK_EX);

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.

 

?>

<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!" />

<input type="hidden" name="submitted" value="true" />

</form>

</body>

</html>

Link to comment
Share on other sites

Jonathon,

I appreciate your reply. I just stuck both files into the htdocs folder and changed the location to: $file = 'quotes.txt'... I had typed text rather than txt. Sorry about wasting your time but thanks for the reply. I had tried a number of things but just overlooked the spelling error.

  • Upvote 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...