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

5
  • can we see your verification.php.? Commented Feb 13, 2017 at 21:27
  • verification.php does not exist yet since I don't know how to store data in it :) Commented Feb 13, 2017 at 21:28
  • PHP write file from input to txt not working for me.. as I said I am really new to PHP Commented Feb 13, 2017 at 21:32
  • So please come back when you have studied a little more. Visit the PHP site Commented Feb 14, 2017 at 7:08
  • Go to more questions and make stupid comments just to get more badges so you can feel good about your self Commented Feb 14, 2017 at 8:19

1 Answer 1

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';
    }
}
Sign up to request clarification or add additional context in comments.

10 Comments

Hi Kamrul,Thanks for the tip in the HTML! I've edited verification.php to look like: <?php if ($_POST) { file_put_contents('/var/www/html/users.txt', $_POST['name']."\n", FILE_APPEND); } But still not working
did you get any error ?
Hi, nope, blank page
can you confirm if you have error reporting on from your php configuration ? apache needs to have permission in the directory you specified.
Hi, I've changed verification.php to: <?php if (!ini_get('display_errors')) { ini_set('display_errors', '1'); } ini_set('error_reporting', E_ALL); if (isset($_POST['name'])) { file_put_contents('/tmp/mydata.txt', $_POST['name']."\n", FILE_APPEND); } Also, i've checked in PHP.INI that display errors is On. Still blank page and no data written into /tmp/mydata.txt
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.