Jump to content

Recommended Posts

Hello, I have this code that writes whatever is typed in the textarea writes to a .txt file (replaces it). When I pull up the "Edit Page" (example) is there a way to show what is already in the txt file in the textarea so that I could change just a part of it rather than going to the .php page that calls the txt file and copy the text, then paste into the textarea on the "Edit Page" to make slight changes? Right now when I pull up the "Edit Page it is a blank textarea. I want the text area to show what is in the txt file currently before revisions. Sorry for the longwindedness :) Code:

 

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<?php
if ($frmSub) { 
$filename="/txt/recentnews.txt";
$fd=fopen("/txt/recentnews.txt","w") or die ("Error opening file in write mode!");
fwrite($fd, $newdata);
fclose($fd) or die ("Error closing file!");
echo "<font color=red>You successfully updated the Recent News section text content on the Home page!</font><br><br>\n";
}
?>

<html> 
<head> 
<title>Edit Recent News Content on Home Page</title> 
<link href="../styles.css" rel="stylesheet" type="text/css" />
</head> 


<body bgcolor="#747474"> 

<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <th scope="col"><p align="left"><a href="index.php"><img src="logo.gif" width="234" height="244" border="0" /></a></p>
      <p align="left"><span class="style23">To update the text in the "Recent News " area on "Home" page, please type in your text below. <br />
            <font color=red><b>NOTE:</b></font> place "<br><br>" when you want to start a new paragraph. (no quotation marks <br><br>).</span><br />
      </p>
      <form action="<? echo $PHP_SELF; ?>" >
        <div align="left">
          <textarea name="newdata" rows="10" cols="90"> 
<? 
echo stripslashes($newdata); 
?> 
        </textarea>
          <br />
          <input type="submit" name="frmSub" value="Update/Change" />
        </div>
      </form>
    <p align="left" class="style23"><a href="index.php">Return to Control Panel main page. </a></p></th>
  </tr>
</table>
</body> 
</html> 

i think your asking for this! (only skimmed the post)

 

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<?php
$filename="/txt/recentnews.txt";
$newdata = $_POST['newdata'];
if (isset($_POST['frmSub']))
{ 
$fd=fopen("/txt/recentnews.txt","w") or die ("Error opening file in write mode!");
fwrite($fd, $newdata);
fclose($fd) or die ("Error closing file!");
echo "<font color=red>You successfully updated the Recent News section text content on the Home page!</font><br><br>\n";
}else{
$handle = fopen($filename, "r");
$newdata= fread($handle, filesize($filename));
fclose($handle);
}
?>

<html> 
<head> 
<title>Edit Recent News Content on Home Page</title> 
<link href="../styles.css" rel="stylesheet" type="text/css" />
</head> 


<body bgcolor="#747474"> 

<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <th scope="col"><p align="left"><a href="index.php"><img src="logo.gif" width="234" height="244" border="0" /></a></p>
      <p align="left"><span class="style23">To update the text in the "Recent News " area on "Home" page, please type in your text below. <br />
            <font color=red><b>NOTE:</b></font> place "<br><br>" when you want to start a new paragraph. (no quotation marks <br><br>).</span><br />
      </p>
      <form method="post">
        <div align="left">
          <textarea name="newdata" rows="10" cols="90"> 
<?php
echo stripslashes($newdata); 
?> 
        </textarea>
          <br />
          <input type="submit" name="frmSub" value="Update/Change" />
        </div>
      </form>
    <p align="left" class="style23"><a href="index.php">Return to Control Panel main page. </a></p></th>
  </tr>
</table>
</body> 
</html> 

 

EDIT:updated

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.