Web Development Exercise 5-2

Feb 4th, 2015
Price: $5 USD

Question description

 Exercise 5-2
In this project, you will create a Web page that allows visitors to your
site to sign a guest book that is saved to a text file. Ensure that the
Projects directory has read and write permissions for everyone.
1.   Create a new document in your text editor and type the
         declaration,  element, document head, and
         element. Use the strict DTD and “Guest Book” as the
        content of the  element.
                   2.   Add the following text and elements to the document body:
                        Enter your name to sign our guest book
                        First Name 
                        Last Name 
Show Guest Book

                   3.   Save the document as GuestBook.html in the Projects direc-
                        tory for Chapter 5.

                   4.   Create a new document in your text editor and type the
                         declaration,  element, document head, and
                         element. Use the strict DTD and “Sign Guest Book” as
                        the content of the  element.

                   5.   Add the following script section to the document body:

                   6.   Add the following if statement to the script section to check
                        whether the user filled in the first name and last name fields:
                        if (empty($_POST['first_name']) || empty($_
                             echo "You must enter your first and last
                                  name. Click your browser's Back button to
                                  return to the Guest Book.\n";

                   7.   Add the following else clause to the end of the script section.
                        The statements in the else clause use the fwrite() function
                        to add visitor names to a text file named guestbook.txt.
                        else {
                             $FirstName = addslashes($_POST['first_name']);
                             $LastName = addslashes($_POST['last_name']);
                             $GuestBook = fopen("guestbook.txt", "ab");
                             if (is_writeable("guestbook.txt")) {
                                  if (fwrite($GuestBook, $LastName . ", " .
                                            $FirstName . "\n"))
                                       echo "Thank you for signing our
                                            guest book!\n";
                                       echo "Cannot add your name to the
                                            guest book.\n";

                   echo "Cannot write to the file.\n";

   8.   Save the document as SignGuestBook.php in the Projects
        directory for Chapter 5.
   9.   Create a document named ShowGuestBook.php that dis-
        plays the names of visitors who have signed the guest book.
        Use the readfile() function to display the contents of the
        guestbook.txt file. Note that you will need to use the 
        element for Web browsers to recognize the line breaks.

  10. Open GuestBook.html in your Web browser by enter-
      ing the following URL: http:///PHP_Projects/
      Chapter.05/Projects/GuestBook.html. Test the form to see if
      you can write data to and read data from the guestbook.txt

  11. Close your Web browser window.

Tutor Answer

(Top Tutor) Willson W
School: University of Virginia

Studypool has helped 1,244,100 students

Review from student
" Goes above and beyond expectations ! "
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1826 tutors are online

Brown University

1271 Tutors

California Institute of Technology

2131 Tutors

Carnegie Mellon University

982 Tutors

Columbia University

1256 Tutors

Dartmouth University

2113 Tutors

Emory University

2279 Tutors

Harvard University

599 Tutors

Massachusetts Institute of Technology

2319 Tutors

New York University

1645 Tutors

Notre Dam University

1911 Tutors

Oklahoma University

2122 Tutors

Pennsylvania State University

932 Tutors

Princeton University

1211 Tutors

Stanford University

983 Tutors

University of California

1282 Tutors

Oxford University

123 Tutors

Yale University

2325 Tutors