Save the input field entry
Ekopop
-
Ekopop -
Ekopop -
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!
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
-
Good evening, do you need JavaScript or PHP
--
hoooo... I have six huge hairy breasts growing on my back -
-
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. -
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.
-
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 -
Thank you very much for your help. If I understand correctly, I still need to use a database like MySQL, right?
-
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 -
-
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...