Form to Flat File in PHP by Jeyrad

In this tutorial you will learn how to take the text from a text field, or text area, and write that information into a flat file. Pay close attention so you dont get any PHP errors.

Step 1

Step 1 is to create the Submission page. Now, make new page in your favorite text editor. Add the following code:


<title>Form to Flat File</title>

<form action="sendinfo.php" method="get">
Your Name:<br />
<input type="text" name="name"><br />
Your Message:<br />
<textarea name="message"></textarea><br />
<input type="submit" value="Send Info">

You have just made the page where you will type the information to be added to the flat file. Save this page with the filename info.php

Step 2

Step 2 is proccessing the info.

We will now make the page that proccesses the info. Make another new page in your text editor and add the following code:

Form to Flat File</title>

$user = $_GET["name"];
$message = $_GET["message"];
print("<b>Thank You!</b><br />Your information has been added! You can see it by <a href=savedinfo.php>Clicking Here</a>");
$out = fopen("savedinfo.php", "a");
if (!$out) {
print("Could not append to file");

fputs ($out,implode,("\n"));
fwrite($out,"<b>$user</b><br />$message<br /><br />");

You have just finished the proccess page. Almost done!

Step 3

Now you must create the page that will display the info, which would be called in this case savedinfo.php