CeEe4 Posted November 25, 2009 Share Posted November 25, 2009 Hi, i am having trouble saving the data entered in my HTML form into .txt format. Here is my crappy HTML form <div id="apDiv3"><h2 class="style3">About you</h2> <p> <form action="write.php" method="get"> <table> <tr><td><span class="style3">What is you name:</span></td><td><input name="Name" type="text" /></td></tr> <tr><td height="26"><span class="style3">favourite Color:</span></td><td align="right"> Blue : <input type="radio" value="Blue" name="col"> :<br /> Red : <input type="radio" value="Red" name="col"> :<br /> Green: <input type="radio" value="Green" name="col"> :<br /> </td> <tr><td><span class="style3">Phone No.:</span></td><td><input name="phone" type="text" /></td></tr> <tr><td colspan="2" align="center"><input name="Start" type="Submit" id="Start" value="Start" /></td></tr> </table> </form> </div> what i need is a php file to save the data entered in the form to a .txt file. if had a go at one here, but like the HTML form i think its not very good.. <?php $Name = $_POST['Name']; $Name = $_POST['col']; $Name = $_POST['phone']; $fp = fopen("output.txt","a+") or exit("unable to open the file"); if($fp != null) { fwrite($fp,$Name); fwrite($fp,$col); fwrite($fp,$phone); } fclose($fp); ?> i could do with some help.. Quote Link to comment https://forums.phpfreaks.com/topic/182931-help-with-saving-form-data/ Share on other sites More sharing options...
phpnewbieca Posted November 25, 2009 Share Posted November 25, 2009 The strings you used to get the information from the form may be the problem! <?php $Name = $_POST['Name']; $Name = $_POST['col']; $Name = $_POST['phone']; $fp = fopen("output.txt","a+") or exit("unable to open the file"); if($fp != null) { fwrite($fp,$Name); fwrite($fp,$col); fwrite($fp,$phone); } fclose($fp); Try this: <?php // Get Information From Form $Name = $_POST['Name']; $Col = $_POST['col']; $Phone = $_POST['phone']; $myfile = "output.txt" $fh = fopen($myfile,'a+'); if(!$fh) { die("couldn't open file <i>$myfile</i>"); } else { $str.= " $Name\r\n"; $str.= " $Col\r\n"; $str.= " $Phone\r\n"; fwrite($fh, $str); } fclose($fh); } GOOD LUCK! Quote Link to comment https://forums.phpfreaks.com/topic/182931-help-with-saving-form-data/#findComment-965540 Share on other sites More sharing options...
deecee2000 Posted November 25, 2009 Share Posted November 25, 2009 Also you need to do this. From <form action="write.php" method="get"> To <form action="write.php" method="post"> Enjoy!!! Quote Link to comment https://forums.phpfreaks.com/topic/182931-help-with-saving-form-data/#findComment-965709 Share on other sites More sharing options...
phpnewbieca Posted December 9, 2009 Share Posted December 9, 2009 You're correct. I didn't notice METHOD="GET" I wonder if it worked???? Quote Link to comment https://forums.phpfreaks.com/topic/182931-help-with-saving-form-data/#findComment-973863 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.