rbotham Posted December 3, 2007 Share Posted December 3, 2007 Hi All, Beginner here I've done a fair bit of reading but can't seem to get an answer on this one. I've a simple one input box html form with some test preceeding the input box. I need to be able to write the text and the variable data in the input box to a file. So if I input "Richard" into the text box I expect to get 'My Name Richard' written to the file Code below <html> <body> <form action="test2.php" method="post"> !<br> My Name <input type="text" name="name" /> <br> !<br> <input type="submit" /> </form> </font> </body> </html> ! php code <?php $filetowrite = "test2.txt"; $fh = fopen($filetowrite,"w") or die ("Cannot open the file"); $name = $_POST["name"]; fwrite($fh, "$name\n"); fclose($fh); ?> Any answers gratefully appreciated Rich Quote Link to comment Share on other sites More sharing options...
helraizer Posted December 3, 2007 Share Posted December 3, 2007 <html> <body> <form action="test2.php" method="post"> ! My Name <input type="text" name="name" /> ! <input type="submit" /> </form> </font> </body> </html> ! php code <?php $filetowrite = "test2.txt"; $fh = fopen($filetowrite,"w") or die ("Cannot open the file"); $name = $_POST["name"]; fwrite($fh, "$name\n"); fclose($fh); ?> Any answers gratefully appreciated Rich Hey Rich, try <?php $fh = fopen("test2.txt", "w"); $name = htmlspecialchars(addslashes(trim($_POST['name'])); $outputstring = "My name is ". $name ."\n"; fwrite($fh, $outputstring); fclose($fh) ?> There is also a php5 function that does them all combined, called file_put_contents. Sam Quote Link to comment Share on other sites More sharing options...
therealwesfoster Posted December 3, 2007 Share Posted December 3, 2007 You only can receive what is inputted in the box.. so if you want "My Name is Richard" instead of just "Richard" (which is what they type) On your php page do this: $name = "My Name Is ".$_POST['name']; That will put "My Name Is" before their name Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.