【问题标题】:PHP - Saving form data to two different text filesPHP - 将表单数据保存到两个不同的文本文件
【发布时间】:2016-06-29 21:04:23
【问题描述】:

我有一个由复选框和文本字段组成的简单 HTML 表单。

当我提交此表单时,它会将数据提交回我捕获数据并将其写入文本文件的同一页面。

我想做的是将一些复选框和字段数据写入一个文本文件,其余的写入另一个。

这可以做到吗?如果可以的话,我该怎么说哪些字段写入了哪个文件?

谢谢

【问题讨论】:

  • 你写代码。 file_put_contents('1.txt', $somevalue); file_put_contents('2.txt', $othervalue);
  • 让我们看看你的代码(贴出来)。
  • 请在此处发布您的代码

标签: php forms submit text-files


【解决方案1】:

您发送表单,然后处理数据。例如:

$dog = $_POST["dog"];
$cat = $_POST["cat"];

$fileForDogs = fopen('path://to/first/file', 'a+'); //a+ means if not exst, create one and write on the end of file
fwrite($fileForDogs, $dog);
fclose($fileForDogs);

$fileForCats = fopen('path://to/second/file', 'a+'); //a+ means if not exst, create one and write on the end of file
fwrite($fileForCats, $cat);
fclose($fileForCats);

我强烈建议查看数据库,例如 mysql 来保存表单中的数据。

【讨论】:

    猜你喜欢
    • 2013-12-22
    • 1970-01-01
    • 1970-01-01
    • 2012-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多