I want my php file to write some text to a text file that I have created but nothing is being written to it.
Here is the code:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
if (isset($_POST['comment']))
{
$comment = $_POST['comment'];
$myFile = "testFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $comment;
fwrite($fh, $stringData);
fclose($fh);
}
else
{
$comment = 'no comment';
$myFile = "testFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $comment;
fwrite($fh, $stringData);
fclose($fh);
}
?>
fwrite()
to see if it returnsfalse
or0
, to see if it's not writing anything or if there's an error writing.$_POST['comment']
is not an empty string?