VicHost Posted October 21, 2010 Share Posted October 21, 2010 Hey folks, I thought this would be simple but obviously not. I can get the data to display in the textarea from the text file. That's not an issue. The issue is, updating the text from the textarea and saving it in the file, while keeping the text in the textarea. Basically, I want to create a personal notepad inside the site I am making. Here is the code I am using: <form action="?admintext.txt" method=post> <textarea name="file_content" class="textarea1"><? include "admintext.txt"; ?></textarea><br/> <input type=submit name=submit value=Update> </form> Can anyone help with this? I tried loads of tips I found from Google but none worked. Quote Link to comment https://forums.phpfreaks.com/topic/216465-submitting-data-to-txt-file-from-textarea/ Share on other sites More sharing options...
Username: Posted October 21, 2010 Share Posted October 21, 2010 Uhhh, don't think this will work considering I've never tried it but.... $visitor_ip = $_SERVER['REMOTE_ADDR']; $myFile = "admintext.txt"; $fh = fopen($myFile, 'r'); $text = fread($fh, filesize($myFile)); fclose($fh); print("<input name='name' value='$text' type='text'>"); just a thought tested it. It didn't work :'( Quote Link to comment https://forums.phpfreaks.com/topic/216465-submitting-data-to-txt-file-from-textarea/#findComment-1124800 Share on other sites More sharing options...
awjudd Posted October 21, 2010 Share Posted October 21, 2010 if ( isset ($_POST ['file_contents']) ) { file_put_contents ('file.txt', $_POST ['file_contents'] ); } Quote Link to comment https://forums.phpfreaks.com/topic/216465-submitting-data-to-txt-file-from-textarea/#findComment-1124818 Share on other sites More sharing options...
VicHost Posted October 21, 2010 Author Share Posted October 21, 2010 if ( isset ($_POST ['file_contents']) ) { file_put_contents ('file.txt', $_POST ['file_contents'] ); } Confusion sets in mate. Where am I putting this? Quote Link to comment https://forums.phpfreaks.com/topic/216465-submitting-data-to-txt-file-from-textarea/#findComment-1124835 Share on other sites More sharing options...
awjudd Posted October 21, 2010 Share Posted October 21, 2010 On the page that is being posted to ... I just noticed that it is being posted to a .txt file ... so you are going to have to change that to a separate php file. ~judda Quote Link to comment https://forums.phpfreaks.com/topic/216465-submitting-data-to-txt-file-from-textarea/#findComment-1124837 Share on other sites More sharing options...
VicHost Posted October 21, 2010 Author Share Posted October 21, 2010 Thanks mate. Same issue. The text from the text file is showing fine inside the textarea. However, if I type something into the textarea and click on Update, it just goes back and displays the text that was oreviously there. Quote Link to comment https://forums.phpfreaks.com/topic/216465-submitting-data-to-txt-file-from-textarea/#findComment-1124840 Share on other sites More sharing options...
awjudd Posted October 21, 2010 Share Posted October 21, 2010 Does php have write permissions on the file? Can you post your updated code (with the code for the file_put_contents) on here so we aren't pulling at straws? ~judda Quote Link to comment https://forums.phpfreaks.com/topic/216465-submitting-data-to-txt-file-from-textarea/#findComment-1124876 Share on other sites More sharing options...
VicHost Posted October 21, 2010 Author Share Posted October 21, 2010 No problem. Here is the form: <form action="?admintext.php" method="post"> <textarea name="content" class="textarea1"><?php include "notes.txt"; ?></textarea> <br /> <input type="submit" value="Save"> </form> admintext.php: <?php if ( isset ($_POST ['file_contents']) ) { file_put_contents ('notes.txt', $_POST ['file_contents'] ); } ?> notes.txt is blank. Quote Link to comment https://forums.phpfreaks.com/topic/216465-submitting-data-to-txt-file-from-textarea/#findComment-1125023 Share on other sites More sharing options...
DavidAM Posted October 22, 2010 Share Posted October 22, 2010 The name of your textarea is not "file_contents" it is "content. So the page code would be: if ( isset ($_POST ['content']) ) { file_put_contents ('notes.txt', $_POST ['content'] ); } Quote Link to comment https://forums.phpfreaks.com/topic/216465-submitting-data-to-txt-file-from-textarea/#findComment-1125046 Share on other sites More sharing options...
VicHost Posted October 22, 2010 Author Share Posted October 22, 2010 The name of your textarea is not "file_contents" it is "content. So the page code would be: if ( isset ($_POST ['content']) ) { file_put_contents ('notes.txt', $_POST ['content'] ); } Nah. Still not updating it mate. http://dano.id.au/admin/index.php?admintext.php You will see what I mean. Note in the textarea it says Style. It's there because I manualy put it into notes.txt So getting the text from notes.txt into the textarea is not an issue. It's submitting text through the textarea to be placed into notes.txt and then displayed in the textarea is the issue. Quote Link to comment https://forums.phpfreaks.com/topic/216465-submitting-data-to-txt-file-from-textarea/#findComment-1125083 Share on other sites More sharing options...
VicHost Posted October 22, 2010 Author Share Posted October 22, 2010 Fixed! Above the HTML tags of the page, I have the following: <?php if ( isset ($_POST ['content']) ) { file_put_contents ('notes.txt', $_POST ['content'] ); } ?> The form is now: <form method="post"> <textarea name="content" cols="" rows="" wrap="virtual" class="textarea1"> <?php include 'notes.txt'; ?> </textarea> <br /> <input type="submit" value="Save"> </form> Works like a charm. Quote Link to comment https://forums.phpfreaks.com/topic/216465-submitting-data-to-txt-file-from-textarea/#findComment-1125130 Share on other sites More sharing options...
awjudd Posted October 22, 2010 Share Posted October 22, 2010 In your form, you had action = '?admintext.php' which wasn't going to post there as you expected, it was going to post to the current page and have ?admintext.php in the URL . ~judda Quote Link to comment https://forums.phpfreaks.com/topic/216465-submitting-data-to-txt-file-from-textarea/#findComment-1125169 Share on other sites More sharing options...
VicHost Posted October 22, 2010 Author Share Posted October 22, 2010 In your form, you had action = '?admintext.php' which wasn't going to post there as you expected, it was going to post to the current page and have ?admintext.php in the URL . ~judda Yeah realised that afterwards. Put it there at first to stop admintext.php from opening in the browser when I clicked save. Then realised that action wasn't needed. Thanks for your help too. Quote Link to comment https://forums.phpfreaks.com/topic/216465-submitting-data-to-txt-file-from-textarea/#findComment-1125173 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.