HTML PHP表单将结果存储在文本文件中

html php form store results in a text file

本文关键字:文本 文件 存储 结果 PHP 表单 HTML      更新时间:2023-09-26

我使用以下html, php代码。一切正常。我可以将html表单提交的值存储到文本文件中。但是当我加载html页面时,我在执行tail -f filename时看到以下内容。

mytext.txt: file truncated
当页面加载或刷新时,

I看起来像没有值的文本文件。我怎么能只写值时提交按钮被点击,而不是写页面加载。

<?php
$action = $_GET["action"];
$customer = $_POST["customer"];
$ourref = $_POST["ourref"];
$custref = $_POST["custref"];
$comments = $_POST["comments"];
$wipe = $_POST["wipe"];

$data = array($customer, $ourref, $custref, $comments, $wipe);
if($action = "save") {
  file_put_contents("mytext.txt", implode(':',$data));
      }
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="main.css">
 <title>Customer Information</title>
</head>
<body>
<div class="wipemain">
<h2> Test </h2>
<h3> This information will be used by the data wiping system </h3>
  <form action="?action=save" name="myform" method="post">
    Enter Customer Name:
    <input type=text size=80 name="customer"></br></br>
    Enter Our Reference Name:
    <input type=text size=76 name="ourref"></br></br>
    Enter Customer Reference Number:
    <input type=text size=69 name="custref"></br></br>
    Comments:
    <input type=text size=91 name="comments"></br></br>
    Select the Data Wiping Method:
    <select name="wipe">
    <option value="zero">Default - Quick and Secure - Write Zeros across the spindles</option>
    <option value="dod522022m">dod522022m / dod       - 7 pass DOD 5220.22-M method</option>
    <option value="dodshort">dodshort / dod3pass    - 3 pass DOD method</option>
    <option value="gutmann">gutmann                - Peter Gutmann's Algorithm</option>
    <option value="ops2">ops2                   - RCMP TSSIT OPS-II</option>
    <option value="random">random / prng / stream - PRNG Stream</option>
    <option value="zero">zero / quick           - Overwrite with zeros</option>
    <option value="dod522022m">U.S. Navy Staff Office Publication NAVSO P-5239-26</option>
    <option value="gutmann">British HMG Infosec Standard 5, Enhanced Standard</option>
    <option value="ops2">New Zealand Government Communications Security Bureau NZSIT 402</option>
    <option value="random">Australian Government ICT Security Manual 2014 - Controls</option>

    </select>
    </br></br>
    <input type="submit" size=40 onclick="clicked" value="save">
  </form>
</div>
<script type="text/javascript">
/** function clicked() {
       if (confirm('Do you wanna to submit? Click here to confirm and close this Window')) {
           yourformelement.submit();
       } else {
           return false;
       }
    } */
function clicked() {
           alert("Successfully Processed - Now you can close this Window job"); }
</script>
</body>
</html>

感谢您的帮助

该消息像所有警告和错误消息一样在stderr上输出。您可以删除所有错误输出:

tail -f file 2> /dev/null

或者只过滤出包含truncate的错误消息:

(tail -f file 2>&1 >&3 3>&- | grep -v truncated >&2 3>&-) 3>&1

或与zshbash:

tail -f file 2> >(grep -v truncated >&2)