我正在尝试将在 HTML 表单中输入的数据保存在文本文件中。我正在使用 php 脚本来执行此操作。当我单击提交按钮时,它不会将数据保存在文本文件中。有人可以告诉我这里出了什么问题。
以下是代码片段 -
HTML 表单 -
<form id="post" name="post" method="post" action="input.php">
Name: <input type="text" name="name"><br>
Text: <textarea rows="50" cols="85" name="blogentry"></textarea>
<input class="button" type="submit" value="Submit">
</form>
PHP - (input.php)
<html>
<head></head>
<body>
<?php
// variables from the form
$name = $_POST['name'];
$blogentry = $_POST['blogentry'];
// creating or opening the file in append mode
$dataFile = "data.txt";
$fh = fopen($dataFile, 'a');
// writing to the file
fwrite($fh, "Name - " . " " . $name . " " . "\n");
fwrite($fh, "Blog - " . " " . $blogentry . " " . "\n\n");
fclose($fh);
?>
</body>
</html>