如何将文本字段中的文本输入保存到文件中? [重复]

This question already has an answer here:

Guys i am a complete noob in PHP, and so i need help with my question. Here is my code:

<div class="form-group">
                  <input id="name" placeholder="test 123" value="" type="name" class="form-control">
                </div>

I would like the name field to be saved to a text file.

</div>

You should specify the input name first.

    <div class="form-group">
<form method="post" action="filename.php">
                      <input id="name" placeholder="test 123" value="" name="name" type="name" class="form-control">
    </form>
                    </div>

Send the post data to the php page. And paste this code there

<?php
$name = $_POST['name'];
file_put_contents("file_name.txt",$name); // Will put the text to file
?>

Hope this helps you