2014-07-24 95 views
0

我正在尝试将PHP脚本写入纯文本文件。我以前做过这件事,它工作得很好。但由于某种原因,这次不起作用。
这里是我使用的HTML:PHP 5.3将内容写入纯文本

<!DOCTYPE html> 
<html lang="en"> 
    <head> 
     <meta charset="utf-8" /> 
     <link rel="stylesheet" type="text/css" href="/css/feedback.css" > 
     <title>Questions, Comments, Suggestions</title> 
    </head> 
    <body> 
     <p class="title">Questions, comments, and suggestions here!</p> 
      <form method="post" name="userFeedback" action="/submit.php"> 
      <textarea id="comments" placeholder="Leave a comment or review here..."></textarea> 
      <textarea id="name" placeholder="Your name here"></textarea> 
      <textarea id="contact" placeholder="Put any means of contact you want to here (optional)"></textarea> 
      <br> 
      <input class="enter" type="submit" value="Enter"> 
     </form> 
    </body> 
</html> 

所有我想这个做的是打印出来无论是进入到平原,PHP 5.3 .txt文件。这里是代码:

$data = ($_POST["comments"] ." || ". $_POST["name"] ." || ". $_POST["contact"]); 
    $data = strip_tags($data); 

    $file = "feedback.txt"; 
    $f = fopen($file, "a+"); 

    fwrite($f, $data . "\n" . "\n"); 

    fclose($f); 

    header ('Location: index.html'); 

请记住,我使用5.3。我确信这里有一个简单的错误。有人可以帮我弄这个吗?先谢谢你!

回答

0

我们明白了!原来,PHP $ _POST方法寻找“name”属性而不是“id”。