Jump to content

Saving content from textarea into a file


Go to solution Solved by fastsol,

Recommended Posts

I am trying to create a program to get input from user in textarea and save that input into a text file.

But this code is only creating an empty file.

<?php
echo <<<_END
<form action="form.php" method="post">
<textarea name="textdata" cols="50" rows="20"></textarea>
<input type="submit" name="submit" value="CLICK ME">
<input type="hidden" name="submit_check" value="1">

</form>
_END;
function write(){
$fname="test.txt";
$fh=fopen($fname,'w');
$data=$_POST['textdata'];
fwrite($fname,$data);
fclose($fh);
}


if(isset($_POST['submit_check'])){
write();
}
?>

 please help me.

sorry for bad english

Edited by mac_gyver
code tags please
  • Solution

I think you're using the wrong var in your frwite().  You open the file with the handle of $fh but then try to use the $fname in the function to write it.  Try this

fwrite($fh,$data);

Example info http://php.net/manual/en/function.fwrite.php

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.