Web Development Exercise 5-2

Feb 4th, 2015
DotaCN
Category:
Computer Science
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($_
                        POST['last_name']))
                             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";
                                  else
                                       echo "Cannot add your name to the
                                            guest book.\n";
                             }


 else
                   echo "Cannot write to the file.\n";
              fclose($GuestBook);
        }

   8.   Save the document as SignGuestBook.php in the Projects
        directory for Chapter 5.
                                                                        291
   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
      file.

  11. Close your Web browser window.

Tutor Answer

(Top Tutor) Daniel C.
(997)
School: UC Berkeley
PREMIUM TUTOR

Studypool has helped 1,244,100 students

8 Reviews


Summary
Quality
Communication
On Time
Value
kevin12622
Dec 4th, 2016
" Goes above and beyond expectations ! "
kiln82
Nov 25th, 2016
" awesome work thanks "
ashleyisgod
Nov 21st, 2016
" Top quality work from this guy! I'll be back! "
likeplum4
Nov 12th, 2016
" Excellent work as usual "
Molly_Moon
Oct 29th, 2016
" AMAZING as always! "
kpcutie
Oct 20th, 2016
" Excellent job "
Hemapathy
Oct 7th, 2016
" all I can say is wow very fast work, great work thanks "
pmallory
Sep 28th, 2016
" Totally impressed with results!! :-) "
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1827 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