web development exercise 5 2

 Exercise 5-2_x000D_
In this project, you will create a Web page that allows visitors to your_x000D_
site to sign a guest book that is saved to a text file. Ensure that the_x000D_
Projects directory has read and write permissions for everyone.
1.   Create a new document in your text editor and type the_x000D_
         declaration,  element, document head, and_x000D_
         element. Use the strict DTD and “Guest Book” as the_x000D_
        content of the  element.
                   2.   Add the following text and elements to the document body:_x000D_
                        Enter your name to sign our guest book_x000D_
                        _x000D_
                        First Name _x000D_
                        Last Name 
Show Guest Book_x000D_
                        _x000D_
_x000D_
                   3.   Save the document as GuestBook.html in the Projects direc-_x000D_
                        tory for Chapter 5._x000D_
_x000D_
                   4.   Create a new document in your text editor and type the_x000D_
                         declaration,  element, document head, and_x000D_
                         element. Use the strict DTD and “Sign Guest Book” as_x000D_
                        the content of the  element._x000D_
_x000D_
                   5.   Add the following script section to the document body:_x000D_
                        _x000D_
_x000D_
                   6.   Add the following if statement to the script section to check_x000D_
                        whether the user filled in the first name and last name fields:_x000D_
                        if (empty($_POST['first_name']) || empty($__x000D_
                        POST['last_name']))_x000D_
                             echo "You must enter your first and last_x000D_
                                  name. Click your browser's Back button to_x000D_
                                  return to the Guest Book.n";_x000D_
_x000D_
                   7.   Add the following else clause to the end of the script section._x000D_
                        The statements in the else clause use the fwrite() function_x000D_
                        to add visitor names to a text file named guestbook.txt._x000D_
                        else {_x000D_
                             $FirstName = addslashes($_POST['first_name']);_x000D_
                             $LastName = addslashes($_POST['last_name']);_x000D_
                             $GuestBook = fopen("guestbook.txt", "ab");_x000D_
                             if (is_writeable("guestbook.txt")) {_x000D_
                                  if (fwrite($GuestBook, $LastName . ", " ._x000D_
                                            $FirstName . "n"))_x000D_
                                       echo "Thank you for signing our_x000D_
                                            guest book!n";_x000D_
                                  else_x000D_
                                       echo "Cannot add your name to the_x000D_
                                            guest book.n";_x000D_
                             }

 else_x000D_
                   echo "Cannot write to the file.n";_x000D_
              fclose($GuestBook);_x000D_
        }_x000D_
_x000D_
   8.   Save the document as SignGuestBook.php in the Projects_x000D_
        directory for Chapter 5._x000D_
                                                                        291_x000D_
   9.   Create a document named ShowGuestBook.php that dis-_x000D_
        plays the names of visitors who have signed the guest book._x000D_
        Use the readfile() function to display the contents of the_x000D_
        guestbook.txt file. Note that you will need to use the _x000D_
        element for Web browsers to recognize the line breaks._x000D_
_x000D_
  10. Open GuestBook.html in your Web browser by enter-_x000D_
      ing the following URL: http:///PHP_Projects/_x000D_
      Chapter.05/Projects/GuestBook.html. Test the form to see if_x000D_
      you can write data to and read data from the guestbook.txt_x000D_
      file._x000D_
_x000D_
  11. Close your Web browser window._x000D_