p0ppins Posted November 24, 2011 Share Posted November 24, 2011 Hi, I have made a basic html site and it has two forms on it. I have the forms linking to a file called process.php. Basically i need to know what code to put in the php file in order for the forms to save whatever is entered in them to a txt file on my server or computer. Or any other easier way to do the same thing, save the content of two forms on my site. Hope i posted this in the right forum subject. Thanks very much for anyone that helps. Quote Link to comment https://forums.phpfreaks.com/topic/251707-need-help-creating-a-server-side-script-to-save-input-from-html-forms/ Share on other sites More sharing options...
Riparian Posted November 24, 2011 Share Posted November 24, 2011 I am no expert. Have you considered using a database.? If you need a text file though I use this code to store as a text file. (create the file first) In this one I am storing just a single number for use as a switch in a program. I read the number, use it, and then change it for next time This bit reads the text file $imageDisplay = fopen("last_idx_image.txt","r"); $imageNumber = fgets($imageDisplay); fclose($imageDisplay); This bit writes data to the text file; $imageDisplay = fopen("last_idx_image.txt","w"); fwrite($imageDisplay, $imageNumber,1000); fclose($imageDisplay); hope it helps Quote Link to comment https://forums.phpfreaks.com/topic/251707-need-help-creating-a-server-side-script-to-save-input-from-html-forms/#findComment-1290881 Share on other sites More sharing options...
btellez Posted November 24, 2011 Share Posted November 24, 2011 Are you having trouble capturing the submitted form data or do you need help on how to store the captured data? Quote Link to comment https://forums.phpfreaks.com/topic/251707-need-help-creating-a-server-side-script-to-save-input-from-html-forms/#findComment-1290883 Share on other sites More sharing options...
p0ppins Posted November 24, 2011 Author Share Posted November 24, 2011 Are you having trouble capturing the submitted form data or do you need help on how to store the captured data? Umm both i think? lol. Sorry i know how to create the html forms. But have no idea how to create the php script to save the entered data into a txt file. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/251707-need-help-creating-a-server-side-script-to-save-input-from-html-forms/#findComment-1290904 Share on other sites More sharing options...
trq Posted November 24, 2011 Share Posted November 24, 2011 Have you tried searching for a tutorial on the subject? There would be literally hundreds of them around. Quote Link to comment https://forums.phpfreaks.com/topic/251707-need-help-creating-a-server-side-script-to-save-input-from-html-forms/#findComment-1290912 Share on other sites More sharing options...
jcbones Posted November 24, 2011 Share Posted November 24, 2011 In short, to stick it into a text file you would need to: <?php $arr[] = "\n"; //start the data off with a new line. foreach($_POST as $key => $value) { //cycle through the post array, and assign the keys and values. $arr[] = $key . '=' . $value; //making the keys and values into a string, assigning them to an array. } $arr[] = '-----------------------------------------------'; //line of separation at the end of current data. $file = 'testing.txt'; //file name you wish to save to. file_put_contents($file,implode("\n",$arr),FILE_APPEND); //append the data (after joining the data with new lines) to the end of the file. //Now let's show our data. echo '<pre>' . file_get_contents($file) . '</pre>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/251707-need-help-creating-a-server-side-script-to-save-input-from-html-forms/#findComment-1290934 Share on other sites More sharing options...
jotorres1 Posted November 24, 2011 Share Posted November 24, 2011 Hey, take a look at how I write to a file. The post is about a file upload, but it also writes to the file. You might learn something. Hope it helps. http://www.jotorres.com/en/2011/10/simple-file-upload-in-php/ Quote Link to comment https://forums.phpfreaks.com/topic/251707-need-help-creating-a-server-side-script-to-save-input-from-html-forms/#findComment-1290961 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.