Im trying to take user input and write into a txt file then display that txt file on the page but it wont write. I dont have any errors either. If i try to run my code on repl.it it works fine. Code:
<!DOCTYPE html>
<html>
<head>
<title>Store form data in .txt file</title>
</head>
<body>
<form method="post">
Enter Your Text Here:<br>
<input type="text" name="textdata"><br>
<input type="submit" name="submit">
</form>
<iframe src="/data.txt"/>
</body>
</html>
<?php
if(isset($_POST['textdata']))
{
$data=$_POST['textdata'];
$fp = fopen('data.txt', 'a');
fwrite($fp, $data);
fclose($fp);
}
?>
Just the fact that you don’t see any errors doesn’t mean there aren’t any. Could you try enabling display errors in your control panel (in the Alter PHP Config menu) and then try to run the script again?
You could also capture the return value of the fwrite function. If it returns false, it means the data was not written correctly.
I think your issue here could be completely unrelated to PHP. I noticed there is no action="" in your <form> tag. Maybe try adding action="page url" to your <form> tag and see if that helps.