-2

I'm a newbie in HTML and PHP. I've created a form using HTML, and I need to retrieve the input data and save it to a text file. For this I created a .php file. But when I submit the form, the answers do not get saved. Also after submitting, the web page shows the content of the php file. I would really appreciate if someone could point out what I'm doing wrong or advise me on what I should do.

Here is my .html file :

<html>
<body>
  
    <h1>Login</h1>
    <form action="config.php">
        <input type="text" name="username" >
        <label for="">Username</label><br>
        <input type="password" name="password">
        <label for="">Password</label>
        <input type="submit" value="Save">
    </form>
  
</body>
</html>

And the .php file :

<?php
    extract($_REQUEST);
    $file=fopen("form-save.txt","a");

    fwrite($file,"name :");
    fwrite($file, $username ."\n");
    fwrite($file,"Password :");
    fwrite($file, $password ."\n");
    fclose($file);
 ?>
Besworks
  • 2,418
  • 12
  • 31
Shay
  • 9
  • [https://stackoverflow.com/questions/24972424/create-or-write-append-in-text-file](This question) will help you. And one big tip `Never ever save plain passwords` especaly in txt files. if your server is not setup correct people can download it easly from your server – Baracuda078 Jun 02 '22 at 10:44
  • This is not a duplicate. The PHP code used to write the file is correct. The issue appears to be that PHP is not installed or configured correctly. – Besworks Jun 02 '22 at 14:46

0 Answers0