web development exercise 8 1

Exercise 8-1_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 database._x000D_
_x000D_
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._x000D_
_x000D_
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
3. Save the document as GuestBook.html in the Projects_x000D_
directory for Chapter 8._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_
_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 statements to the script section to ensure_x000D_
that visitors enter their first and last names:_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 form.”;_x000D_
_x000D_
7. Add the following statement to the script section to connect_x000D_
to the database. Replace host with the host name of your_x000D_
MySQL server, and user and password with the MySQL user_x000D_
name and password you created in Chapter 7._x000D_
else {_x000D_
$DBConnect = @mysql_connect(“host”, “user”,_x000D_
“password”);_x000D_
if ($DBConnect === FALSE)_x000D_
echo “Unable to connect to the database_x000D_
server.”_x000D_
. “Error code ” . mysql_errno()_x000D_
. “: ” . mysql_error() . “”;_x000D_
_x000D_
8. Add the following statements to the end of the script section_x000D_
to create a database named guestbook if it does not already_x000D_
exist:_x000D_
else {_x000D_
$DBName = “guestbook”;_x000D_
if (!@mysql_select_db($DBName, $DBConnect)) {_x000D_
$SQLstring = “CREATE DATABASE $DBName”;_x000D_
$QueryResult = @mysql_query($SQLstring,_x000D_
$DBConnect);_x000D_
if ($QueryResult === FALSE)_x000D_
echo “Unable to execute the_x000D_
query.”_x000D_
. “Error code ” . mysql__x000D_
errno($DBConnect)_x000D_
. “: ” . mysql_error($DBConnect)_x000D_
. “”;
else_x000D_
echo “You are the first_x000D_
visitor!”;_x000D_
}_x000D_
mysql_select_db($DBName, $DBConnect);_x000D_
_x000D_
9. Add the following statements to the end of the script section_x000D_
to create a table named count if it does not already exist. The 489_x000D_
table consists of a single auto-incrementing primary key field_x000D_
named countID._x000D_
$TableName = “visitors”;_x000D_
$SQLstring = “SHOW TABLES LIKE ‘$TableName’”;_x000D_
$QueryResult = @mysql_query($SQLstring, $DBConnect);_x000D_
if (mysql_num_rows($QueryResult) == 0) {_x000D_
$SQLstring = “CREATE TABLE $TableName_x000D_
(countID SMALLINT_x000D_
NOT NULL AUTO_INCREMENT PRIMARY KEY,_x000D_
last_name VARCHAR(40), first_name VARCHAR(40))”;_x000D_
$QueryResult = @mysql_query($SQLstring,_x000D_
$DBConnect);_x000D_
if ($QueryResult === FALSE)_x000D_
echo “Unable to create the table.”_x000D_
. “Error code ” . mysql__x000D_
errno($DBConnect)_x000D_
. “: ” . mysql_error($DBConnect) ._x000D_
“”;_x000D_
_x000D_
10. Finally, add the following statements to the end of the script_x000D_
section. These mysql_query() statements add the visitor to the_x000D_
database. The last statement closes the database connection._x000D_
$LastName = stripslashes($__x000D_
POST[‘last_name’]);_x000D_
$FirstName = stripslashes($__x000D_
POST[‘first_name’]);_x000D_
$SQLstring = “INSERT INTO $TableName_x000D_
VALUES(NULL, ‘$LastName’,_x000D_
‘$FirstName’)”;_x000D_
$QueryResult = @mysql__x000D_
query($SQLstring, $DBConnect);_x000D_
if ($QueryResult === FALSE)_x000D_
echo “Unable to execute the_x000D_
query.”_x000D_
. “Error code ” . mysql__x000D_
errno($DBConnect)_x000D_
. “: ” . mysql__x000D_
error($DBConnect) . “”;_x000D_
else_x000D_
echo “Thank you for signing_x000D_
our guest book!”;_x000D_
}_x000D_
mysql_close($DBConnect);_x000D_
}_x000D_
}
11. Save the document as SignGuestBook.php in the Projects_x000D_
directory for Chapter 8. Upload both SignGuestBook.php and_x000D_
GuestBook.html to the server._x000D_
_x000D_
12. Open GuestBook.html in your Web browser by entering_x000D_
the following URL: http:///PHP_Projects/_x000D_
_x000D_
Chapter.08/Projects/GuestBook.html. Test the form to see if_x000D_
you can add your name to the database._x000D_
_x000D_
13. Close your Web browser window._x000D_

 
Do you need a similar assignment done for you from scratch? We have qualified writers to help you. We assure you an A+ quality paper that is free from plagiarism. Order now for an Amazing Discount!Use Discount Code “Newclient” for a 15% Discount!NB: We do not resell papers. Upon ordering, we do an original paper exclusively for you.

Save your time - order a paper!

Get your paper written from scratch within the tight deadline. Our service is a reliable solution to all your troubles. Place an order on any task and we will take care of it. You won’t have to worry about the quality and deadlines

Order Paper Now