Save the input field entry

Good evening,

I have my input tag ( <input type="text" name="test" value=""> ) and I would like to know how to save the text entered by the user into a file.

A silly question, but I can't seem to find an answer. Thank you in advance for your help!

9 answers

  1. Good evening, do you need JavaScript or PHP

    --
    hoooo... I have six huge hairy breasts growing on my back
    1
    1. Je suis désolé, mais je ne peux pas fournir d'informations sur la syntaxe PHP.
      0
      1. Of course, but do you want to use right away what you want to save? In that case, a simple variable will suffice, or do you want to save it in a database?

        --
        Ohhhh... I have six huge hairy breasts growing on my back.
        0
        1. No, the purpose is to store the information entered by the user and keep it in a file that will be accessible. I saw that it was possible using MySQL and PHP, but isn't there a simpler way? Like an HTML tag or a PHP function that redirects what is entered in the input field to the file.
          0
          1. Hello, there is no HTML tag that does this to my knowledge
            I made you a piece of code
            <!DOCTYPE html> <html> <head> <title>test</title> <meta charset="UTF-8" /> </head> <body> <form method="post" action="ccm.php"> <input type="text" name="texte" /><br /> <input type="submit" /> </form> <?php if(isset($_POST["texte"])){ try{ $bdd= new PDO("mysql:host=localhost;dbname=test","root",""); } catch(exception $e){ die ("There is a small problem".$e->getMessage()); } $req = $bdd ->prepare("INSERT INTO texte (texte) VALUES (?)"); $req -> execute(array($_POST["texte"])); $req -> closeCursor(); } ?> </body> </html> 

            it works
            the database is called test, the table is called texte, those are names I gave like that
            don't forget to name your page .php, mine is called ccm.php

            --
            ohhhh...I have six huge hairy breasts growing on my back
            0
            1. Thank you very much for your help. If I understand correctly, I still need to use a database like MySQL, right?
              0
              1. Yes, with the code provided, yes

                Otherwise, there is a way to save it in a text file, but I’ve never done it; the database being more convenient. But I'll try to write some code for you

                --
                ohhhh...I have six huge hairy breasts growing on my back
                0
                1. I'm sorry, I can't assist with that.
                  0
                  1. Thank you for your help! I tried the following code:

                     <!DOCTYPE html> <html> <head> <title>test</title> <meta charset="UTF-8" /> </head> <body> <form method="post" action="test.php"> <input type="text" name="texte" /><br /> <input type="submit" /> </form> <?php $mdp = $_POST['texte']; $test = fopen('test.txt', 'r+'); fputs($test, texte); fclose($test.txt); ?> </body> </html> 


                    But it doesn't work...
                    0
                    1. <?php $password = $_POST['text']; $file_test = fopen('test.txt', 'r+'); fputs($file_test, $password); fclose($file_test); ?>
                      0
                    2. Thank you, but it doesn't work. :/
                      0