Jump to content

Saving content from textarea into a file


govindJ

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.