【发布时间】:2018-06-22 23:43:11
【问题描述】:
我在这个网站上搜索了答案,但找不到任何答案。
我有一个表单,我想将输入的内容写入一个 txt 文件。为了简单起见,我只写了一个简单的表单和一个脚本,但它总是让我看到一个空白页。这是我得到的
<html>
<head>
<title></title>
</head>
<body>
<form>
<form action="myprocessingscript.php" method="post">
<input name="field1" type="text" />
<input name="field2" type="text" />
<input type="submit" name="submit" value="Save Data">
</form>
<a href='data.txt'>Text file</a>
</body>
这是我的 PHP 文件
<?php
$txt = "data.txt";
$fh = fopen($txt, 'w+');
if (isset($_POST['field1']) && isset($_POST['field2'])) { // check if both fields are set
$txt=$_POST['field1'].' - '.$_POST['field2'];
file_put_contents('data.txt',$txt."\n",FILE_APPEND); // log to data.txt
exit();
}
fwrite($fh,$txt); // Write information to the file
fclose($fh); // Close the file
?>
【问题讨论】:
-
myprocessingscript.php是否产生任何进一步的输出?如果您的第二个 sn-p 是整个 PHP 脚本,那么您应该得到一个空白页面,因为您没有生成任何输出。 -
你得到一个空白页也是正常的,你对客户没有任何
echo()ing。
标签: php