Jump to content

Submitting data to txt file from textarea


VicHost

Recommended Posts

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.

Link to comment
Share on other sites

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  :'(

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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. :)

Link to comment
Share on other sites

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. :)

Link to comment
Share on other sites

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.