Pr0digy Posted November 5, 2008 Share Posted November 5, 2008 Hi folks, I have a simple HTML form and i want the site to record what someone puts in there. Is there a way to have it saved to a text file on the server after someone hits "submit" ? It's just one word that's being entered. Here's the form code: <form action="test.php" method="post" target="TestFrame"> <strong><br /> <br /> <br /> Enter Namel</strong> <input type="text" name="name" id="name" value="" onChange="javascript:this.value=this.value.toUpperCase();"/> <input type="submit"> <br /> </form> I REALLY want to avoid stuff like databases etc since the word 'database' alone scares me Thanks for any help Jay Quote Link to comment https://forums.phpfreaks.com/topic/131450-solved-record-form-entry-to-text-file-possible/ Share on other sites More sharing options...
Pr0digy Posted November 5, 2008 Author Share Posted November 5, 2008 Sorry i forgot to add "i was told PHP is the way to go to get this done". Problem is... i have no clue where to start :S Quote Link to comment https://forums.phpfreaks.com/topic/131450-solved-record-form-entry-to-text-file-possible/#findComment-682693 Share on other sites More sharing options...
JasonLewis Posted November 5, 2008 Share Posted November 5, 2008 You can't avoid them forever! Database's make life SO much easier. But yes, you can write to files with functions like: The old: fopen() fwrite() The new: file_get_contents() (Although it was around back in PHP4) file_put_contents() Hopefully the manual gives you a bit of a push. Good luck. Any problems, just post them here. But try and attempt it yourself. Quote Link to comment https://forums.phpfreaks.com/topic/131450-solved-record-form-entry-to-text-file-possible/#findComment-682699 Share on other sites More sharing options...
Pr0digy Posted November 5, 2008 Author Share Posted November 5, 2008 Hey thanks for the reply, looks promising Do you have a site like that that shows an example script or anything working with a form, just 1 line is nice but i wouldn't know where to put it :S If it's a matter of putting it between <?php and ?> tags and changing some path names i'd be fine Jay Quote Link to comment https://forums.phpfreaks.com/topic/131450-solved-record-form-entry-to-text-file-possible/#findComment-682701 Share on other sites More sharing options...
JasonLewis Posted November 5, 2008 Share Posted November 5, 2008 Okay, to work with a form then take a look at this. You can also search google for handling form data with PHP. Quote Link to comment https://forums.phpfreaks.com/topic/131450-solved-record-form-entry-to-text-file-possible/#findComment-682705 Share on other sites More sharing options...
Pr0digy Posted November 5, 2008 Author Share Posted November 5, 2008 I don't know how you got there so fast but after google page 34 i gave up I will look at this after i wake up with fresh rested eyes and start messing around (almost 6:30 AM here), thanks so much for the help so far jay Quote Link to comment https://forums.phpfreaks.com/topic/131450-solved-record-form-entry-to-text-file-possible/#findComment-682708 Share on other sites More sharing options...
JasonLewis Posted November 5, 2008 Share Posted November 5, 2008 Haha. Take a look at this page on Pixel2Life. It's a bunch of form related tutorials. Quote Link to comment https://forums.phpfreaks.com/topic/131450-solved-record-form-entry-to-text-file-possible/#findComment-682724 Share on other sites More sharing options...
Fluf Posted November 5, 2008 Share Posted November 5, 2008 http://www.tizag.com/phpT/filecreate.php Try this one Quote Link to comment https://forums.phpfreaks.com/topic/131450-solved-record-form-entry-to-text-file-possible/#findComment-682725 Share on other sites More sharing options...
Pr0digy Posted November 5, 2008 Author Share Posted November 5, 2008 Thanks for the links I browsed around on Pixel2Life and found this (hopefully promising) snippet and link... require('log.php'); <?php function log_action($msg) { if ($fp = @fopen("/var/lib/mysql/php_app.log", "a")) { fwrite($fp, $msg, strlen($msg)); fclose($fp); } } ?> And this is a link: http://www.gfx-depot.com/forum/-tutorial-index-t-1040.html I think most of what i need is there but im still lost as how to merge this kind of code with my form and make it work. I have a plain text file on the server called "test.txt". I will keep messing around with this but if someone knows how to get this code to work i might even get this done before the end of the year Jay Quote Link to comment https://forums.phpfreaks.com/topic/131450-solved-record-form-entry-to-text-file-possible/#findComment-682868 Share on other sites More sharing options...
Pr0digy Posted November 6, 2008 Author Share Posted November 6, 2008 i got it to delete the file once, but that's it haha Quote Link to comment https://forums.phpfreaks.com/topic/131450-solved-record-form-entry-to-text-file-possible/#findComment-683316 Share on other sites More sharing options...
Pr0digy Posted November 6, 2008 Author Share Posted November 6, 2008 Well i think i've gotten as far as i can.. <form action="serial.php" method="POST" target="MacSerial2Frame"> <strong><br /> <br /> <br /> try it</strong> <input type="text" name="serial" id="serial" value="" onChange="javascript:this.value=this.value.toUpperCase();"/> <input type="submit" value="Get Info"> <br /> </form> <?php $handle = fopen("textfile.txt","a"); $content = $_POST['serial']; fwrite($handle, "test"); fclose($handle); ?> This results in 'test' being written in the textfile. Instead of test i want it to write the contents of the form (that's where the $content = $_POST['serial']; comes in) or so i thought... because it doesn't work. I'm stuck, any help greatly apreciated Jay Quote Link to comment https://forums.phpfreaks.com/topic/131450-solved-record-form-entry-to-text-file-possible/#findComment-683397 Share on other sites More sharing options...
JasonLewis Posted November 6, 2008 Share Posted November 6, 2008 Make it this: <form action="serial.php" method="POST" target="MacSerial2Frame"> <strong><br /> <br /> <br /> try it</strong> <input type="text" name="serial" id="serial" value="" onChange="javascript:this.value=this.value.toUpperCase();"/> <input type="submit" name="submit" id="submit" value="Get Info"> <br /> </form> <?php if(isset($_POST['submit'])){ $handle = fopen("textfile.txt","a"); $content = $_POST['serial']; fwrite($handle, $content); fclose($handle); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/131450-solved-record-form-entry-to-text-file-possible/#findComment-683398 Share on other sites More sharing options...
Pr0digy Posted November 6, 2008 Author Share Posted November 6, 2008 no luck nothing happens except now it stops writing test. Quote Link to comment https://forums.phpfreaks.com/topic/131450-solved-record-form-entry-to-text-file-possible/#findComment-683399 Share on other sites More sharing options...
xcoderx Posted November 6, 2008 Share Posted November 6, 2008 <?php $saving = $_REQUEST['saving']; if ($saving == 1) { $data = $_POST['data']; $file = "data.txt"; $fp = fopen($file, "w") or die("Couldn't open $file for writing!"); fwrite($fp, $data) or die("Couldn't write values to file!"); fclose($fp); echo "Saved to $file successfully!"; } ?> <form name="form1" method="post" action="form.php?saving=1"> <textarea name="data" cols="100" rows="10"> <?php $file = "data.txt"; if (!empty($file)) { $file = file_get_contents("$file"); echo stripslashes($file); } ?> </textarea> <br> <input type="submit" value="Save"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/131450-solved-record-form-entry-to-text-file-possible/#findComment-683447 Share on other sites More sharing options...
Pr0digy Posted November 6, 2008 Author Share Posted November 6, 2008 I think i was doing ok but this doesn't look anything like my form so i don't know how to merge this code... with my stuff :/ Quote Link to comment https://forums.phpfreaks.com/topic/131450-solved-record-form-entry-to-text-file-possible/#findComment-683620 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.