Updating a text file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Squiggy45
Forum Newbie
Posts: 3
Joined: Thu Feb 18, 2010 1:56 pm

Updating a text file

Post 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>";
}
?>
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Updating a text file

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Squiggy45
Forum Newbie
Posts: 3
Joined: Thu Feb 18, 2010 1:56 pm

Re: Updating a text file

Post 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.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Updating a text file

Post by AbraCadaver »

What are the errors on the page after you click Update?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Squiggy45
Forum Newbie
Posts: 3
Joined: Thu Feb 18, 2010 1:56 pm

Re: Updating a text file

Post 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.
Post Reply