Jump to content

Read and save textarea to text file


moe

Recommended Posts

Hi Guys;

 

I am trying to read a text file into a text area allow changes to the text then save the text back to the file on submit. (hope that makes sense :D )

 

Here is the code:

 

 

<?php

if($_POST['addition']){
$file_name = "something.txt";

$file_open = fopen("something.txt","a+");
fwrite($file_open, $_POST['addition']);
fclose($file_open);
}
?>

<form action="<?=$PHP_SELF?>" method="POST">
<textarea name="addition" COLS=40 ROWS=6>
<?php
$datalines = file ("something.txt");

foreach ($datalines as $zz) {
echo $zz; }

?>
</textarea>

<input type="submit" name="addition">

 

It does not seem to be saving the text back.

 

Any help would be great.

 

Oh yeah this is a multi-line (list) text file - as in:

1

2

3

4

etc

etc

 

Cheers;

Moe

Link to comment
Share on other sites

you have given same name for  submit button and text area

 

also make sure that you hv write permission to file

 

below code is working try it

<?php

if($_POST['addition']){


$file_open = fopen("something.txt","w+"); //fopen("something.txt","a+"); to add the contents to file
fwrite($file_open, $_POST['addition']);
fclose($file_open);
}
?>

<form action="<?=$PHP_SELF?>" method="POST">
<textarea name="addition" COLS=40 ROWS=6>
<?php
$datalines = file ("something.txt");

foreach ($datalines as $zz) {
echo $zz; }

?>
</textarea>

<input type="submit" name="button">
    </form>

;) ;) ;) ;)

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.