Jump to content

Need help creating a server side script to save input from html forms


Recommended Posts


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.

Link to comment
Share on other sites

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




Link to comment
Share on other sites

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.


Link to comment
Share on other sites

In short, to stick it into a text file you would need to:


$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>';

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.