m_tyhurst2002 Posted October 5, 2007 Share Posted October 5, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/71942-showing-txt-file-in-textarea-before-re-writing-it/ Share on other sites More sharing options...
MadTechie Posted October 5, 2007 Share Posted October 5, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/71942-showing-txt-file-in-textarea-before-re-writing-it/#findComment-362338 Share on other sites More sharing options...
Guardian-Mage Posted October 5, 2007 Share Posted October 5, 2007 $newdata should be set to the contents of the .txt file. If you do not know how to do this, google PHP File, or PM me. I would write the code but I have to go to school now Quote Link to comment https://forums.phpfreaks.com/topic/71942-showing-txt-file-in-textarea-before-re-writing-it/#findComment-362339 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.