0

I have the following code

<div id="mailbox">
  <form action="verification.php" method="post">
  <input placeholder="Enter your email" type="mail" name="name" style="width:270px; 
   height:42px; border: solid 1px #c2c4c6; font-size:16px; padding-left:8px;" />
</div>
<div>
  <form action="verification.php" method="post">
  <input type="submit" id="button2" value="Next" />
</div>

I want if a user put an input in the enter your email placeholder - it will save the input into a text file.

I have no idea what code I need to write in verification.php. I have 2 days knowledge in PHP.

I want every input a user put in the form, will be saved to user.txt file on my machine.

Thank you

Jprada
  • 97
  • 13
user347977
  • 17
  • 2

1 Answers1

0

I would do something like this:

First change your HTML to:

<div id="mailbox">
  <form action="verification.php" method="post">
    <input placeholder="Enter your email" type="mail" name="name" style="width:270px; height:42px; border: solid 1px #c2c4c6; font-size:16px; padding-left:8px;" />
    <input type="submit" id="button2" value="Next" />
  </form>
</div>

Then, verification.php (make sure you have all error reporting on)

<?php
if (!ini_get('display_errors')) {
    ini_set('display_errors', '1');
}
ini_set('error_reporting', E_ALL);

if (isset($_POST['name'])) {
    echo 'Data received, writing to file <br/>';
    if (!file_put_contents('/path/to/filename', $_POST['name']."\n", FILE_APPEND)) {
        echo 'Sorry! unable to write to the file specified';
    } else {
        echo 'data written to file';
    }
}
Kamrul Khan
  • 3,260
  • 4
  • 32
  • 59