Skip to main content
Inspiring
February 9, 2007
Question

quotations

  • February 9, 2007
  • 5 replies
  • 415 views
hey guys. I am trying to get this quotation to work, i changed file / folder permitions to '646' CODE but when i open add_quote.php and submit a message here : http://therainbowpride.com/myphptests/add_quote.php i get this error :

Warning: fopen(../quotes.txt): failed to open stream: Permission denied in /home/therainb/public_html/myphptests/add_quote.php on line 20

Your quotation could not be stored due to a system error.



this is my php code :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Add A Quotation</title>
</head>
<body>
<?php // Script 11.1 - add-quote.php
// This script displays and handles an HTML form.
// This script takes text input and stores it in a text file.

// Address error handling.
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);

if (isset ($_POST['submit'])) { // Handle form.

if ( !empty ($_POST['quote']) ) { // Check for the requiered value.

if ($fp = fopen ('../quotes.txt', 'ab')) { // Try to open file.

// Adjust for magic quotes.
if (ini_get ('magic_quotes_gpc')) {
$data = stripslashes ($_POST['quote']);
} else {
$data = $_POST['quote'];
}

fwrite ($fp, "$data\n"); // Write the data. Use \r\n on Windows.
fclose ($fp); // Close the file.

// Print a message.
print "<p>Your quotation has been stored.</p>";

} else { // Could not open the file.
print "<p>Your quotation could not be stored due to a system error.</p>";
}
} else { // Failed to enter a quotation.
print "<p>Please enter a quotation!</p>";
}

} // End of SUBMIT IF.

// Leave PHP and display the form.
?>

<form action="add_quote.php" method="post">
<p>
<textarea name="quote" rows="5" columns="30">Enter your quotation here.</textarea>
<br />
<input type="submit" name="submit" value="Add This Quote!" />
</p>
</form>
</body>
</html>


Can someone help me out? I can seem to find where the error is at .
Thank you so much
This topic has been closed for replies.

5 replies

Inspiring
February 10, 2007
ok, thanks you so much
Inspiring
February 9, 2007
LuisDesigns wrote:
> and i removed the ../ leaving as ('quotes.txt') and it worked.
>
> is it normal?

If the text file is in the same folder as the script, of course it's normal.

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Inspiring
February 9, 2007
ok, i got it to work. i dont know if this is normal , but i had to change this :

it was : if ($fp = fopen ('../quotes.txt', 'ab')) { // Try to open file.

and i removed the ../ leaving as ('quotes.txt') and it worked.

is it normal?

thanks
Inspiring
February 9, 2007
i changed it to 666 and still get the same error.
is this normal ?
Inspiring
February 9, 2007
LuisDesigns wrote:
> hey guys. I am trying to get this quotation to work, i changed file / folder
> permitions to '646' CODE but when i open add_quote.php : and type a message i
> get this error :
> Warning: fopen(../quotes.txt): failed to open stream: Permission denied in
> /home/therainb/public_html/myphptests/add_quote.php on line 20


It's a permissions error. 4 is read only. Try 666.

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/