Hello everyone I am very new to php. I am self taught and if possible could you please take me through this slow. I'm basically trying to make a form in PHP that when I submit will save the information in a text file. <form id="login_form" action=post.php method="post" autocomplete="off"> <div class="section_form"> <span style="float: left">Name:</span> <input style="float: right" size="20" type="text" name="name" maxlength="12"> <br class="clear"> </div> <div class="section_form"> <span style="float: left">Password:</span> <input style="float: right" size="20" type="password" name="password" maxlength="20"> <br class="clear"> </div> <div class="section_form"> <input type="submit" value="submit"> </div> PHP: So what I was wondering was how do I get the persons name and password to save into a text file? Do I do something in post.php? Help me confused
in your post.php $myFile = "testFile.txt"; $fh = fopen($myFile, 'a') or die("can't open file"); $stringData = $_POST["name"].",".$_POST["password"]."\n"; fwrite($fh, $stringData); fclose($fh);
You can do it with 1 line. post.php: file_put_contents('file.txt', implode('|', $_POST) . PHP_EOL, FILE_APPEND); PHP:
yea, i forgot about that =) but i think it's better to treat first the $_POST values since, if i'm not mistaken, using your code it will store the submit button value too.