Jack Nilan            EMail : jacknilan@yahoo.com

PHP Writer Lesson

You are going to need to create four files for this lesson. We are going to need an HTML file called test.html that we are going to be writing to, we are going to need and enter.html which will have two textarea boxes where we will enter our information and we will have two PHP files which will receive information from our textarea boxes and will then update our test.html web page.

First create an HTML Page on your site called test.html

then save your file. This is the file we are going to write to.

Create a page that will let you enter information into a textarea. We are going to have two text area boxes. If we enter into the first one we will rewrite the test.html page. If we eneter in the second box, we will add to what was on the test.html page.

Enter something to Write to your page:

Enter something to add on to your page :

Code for above

<FORM METHOD="POST" ACTION="phpwriter.php">
Enter something to Write to your page:<BR>
<INPUT TYPE="reset">
<INPUT TYPE="submit" NAME="submit" VALUE="Submit">

The code for the second textarea box will be exactly the same except send the form info to phpappend.php instead of to phpwrite.php.

The Code for phpwriter.php

$p = $_POST['stuff'];
$File = "test.html";
$Handle = fopen($File, 'w');
fwrite($Handle, $p);

Note how the php file receives the info in $p and then writes it to the HTML page.

The phpappend.php code is exactly the same except we use
$Handle = fopen($File, 'a');

in place of

$Handle = fopen($File, 'w');

The 'a' tells the program to append (add on) to the file instead of writing over it.