Page 1 of 1

Updating a text file

Posted: Thu Feb 18, 2010 1:59 pm
by Squiggy45
This code worked on another server to update a text file, but is not working now. PHP is definitely running on the server, and the text files are where they need to be. Here's the code I inherited (I don't know PHP - just modifying an already-existing site)

<?
if($_POST['Submit']){
$open = fopen("time1.txt","w+");
$text = $_POST['update'];
fwrite($open, $text);
fclose($open);
echo "File updated.<br />";
echo "File:<br />";
$file = file("time1.txt");
foreach($file as $text) {
echo $text."<br />";
}
echo "<p><a href=\"./fundraising.htm\">click here to view the live updated webpage</a></p>";
echo "<p><a href=\"./fundraising-edit.php\">click here to view the admin menu</a></p>";
}else{
$file = file("time1.txt");
echo "<form action=\"".$PHP_SELF."\" method=\"post\">";
echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">";
foreach($file as $text) {
echo $text;
}
echo "</textarea>";
echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n
</form>";
}
?>

Re: Updating a text file

Posted: Thu Feb 18, 2010 2:14 pm
by AbraCadaver
What's not working? You need to turn on error reporting and see what errors you get, but I would assume that if you replace <? with <?php it will help.

Re: Updating a text file

Posted: Thu Feb 18, 2010 4:15 pm
by Squiggy45
OK, the errors say:

Notice: Undefined index: Submit in D:\Inetpub\DomainID198880\pages\fundraising-time1.php on line 57

Notice: Undefined variable: PHP_SELF in D:\Inetpub\DomainID198880\pages\fundraising-time1.php on line 72

Line 57 is the first line of php code:
if($_POST['Submit']){

Line 72 is:
echo "<form action=\"".$PHP_SELF."\" method=\"post\">";

This is after having added the "php" after the question mark.

Re: Updating a text file

Posted: Fri Feb 19, 2010 10:17 am
by AbraCadaver
What are the errors on the page after you click Update?

Re: Updating a text file

Posted: Fri Feb 19, 2010 2:31 pm
by Squiggy45
You got me on the right track. When I looked at the errors, it pointed to file permission issues. All fixed and working. Thanks folks.