Question

PHP Programming In this project, you will create a Web page that allows visitors to your...

PHP Programming

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 database.

  1. Create a new document in your text editor and type the <!DOCTYPE> declaration, <html> element, document head, and <body> element. Use the strict DTD and “Guest Book” as the content of the <title> element.

  2. Add the following text and elements to the document body:

          <h2>Enter your name to sign our guest book</h2>
          <form method="POST" action="SignGuestBook.php">
          <p>First Name <input type="text" name="first_name"
          /></p>
    
          <p>Last Name <input type="text" name="last_name"
          /></p>
          <p><input type="submit" value="Submit" /></p>
          </form>
    
  3. Save the document as GuestBook.html in the Projects

    directory for Chapter 8.

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

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

    <?php ?>

  6. Add the following statements to the script section to ensure that visitors enter their first and last names:

             if (empty($_POST['first_name']) || empty($_
             POST['last_name']))
    
                  echo "<p>You must enter your first and last
                       name! Click your browser's Back button to
                       return to the Guest Book form.</p>";
    
  7. Add the following statement to the script section to connect to the database. Replace host with the host name of your MySQL server, and user and password with the MySQL user name and password you created in Chapter 7.

    else {
    $DBConnect = @mysql_connect("host", "user", "password");
    if ($DBConnect === FALSE)

                       echo "<p>Unable to connect to the database
                            server.</p>"
    
                            . "<p>Error code " . mysql_errno()
                            . ": " . mysql_error() . "</p>";
    
  8. Add the following statements to the end of the script section to create a database named guestbook if it does not already exist:

    else {
    $DBName = "guestbook";
    if (!@mysql_select_db($DBName, $DBConnect)) {

                          $SQLstring = "CREATE DATABASE $DBName";
                          $QueryResult = @mysql_query($SQLstring,
                          $DBConnect);
                          if ($QueryResult === FALSE)
    
                               echo "<p>Unable to execute the
                                    query.</p>"
    
                               . "<p>Error code " . mysql_
                               errno($DBConnect)
                               . ": " . mysql_error($DBConnect)
    

    . "</p>";

else
echo "<p>You are the first

visitor!</p>"; mysql_select_db($DBName, $DBConnect);

  1. Add the following statements to the end of the script section to create a table named count if it does not already exist. The table consists of a single auto-incrementing primary key field named countID.

    $TableName = "visitors";
    $SQLstring = "SHOW TABLES LIKE '$TableName'"; $QueryResult = @mysql_query($SQLstring, $DBConnect); if (mysql_num_rows($QueryResult) == 0) {

    $SQLstring = "CREATE TABLE $TableName (countID SMALLINT
    NOT NULL AUTO_INCREMENT PRIMARY KEY, last_name VARCHAR(40), first_name VARCHAR(40))"; $QueryResult = @mysql_query($SQLstring, $DBConnect);

    if ($QueryResult===FALSE)
    echo "<p>Unable to create the table.</p>"

                         . "<p>Error code " . mysql_
                         errno($DBConnect)
                         . ": " . mysql_error($DBConnect) .
                         "</p>";
    
  2. Finally, add the following statements to the end of the script section. These mysql_query() statements add the visitor to the database. The last statement closes the database connection.

                        $LastName = stripslashes($_
                        POST['last_name']);
                        $FirstName = stripslashes($_
                        POST['first_name']);
                        $SQLstring = "INSERT INTO $TableName
                        VALUES(NULL, '$LastName',
                        '$FirstName')";
    
                        $QueryResult = @mysql_
                        query($SQLstring, $DBConnect);
                        if ($QueryResult === FALSE)
    
                             echo "<p>Unable to execute the
                                  query.</p>"
    
                                . "<p>Error code " . mysql_
                                errno($DBConnect)
                                . ": " . mysql_
                                error($DBConnect) . "</p>";
    
                        else
                             echo "<h1>Thank you for signing
    
                                  our guest book!</h1>";
    

    }

                   mysql_close($DBConnect);
              }
    

    }

  3. Save the document as SignGuestBook.php in the Projects directory for Chapter 8. Upload both SignGuestBook.php and GuestBook.html to the server.

  4. Open GuestBook.html in your Web browser by entering the following URL: http://<yourserver>/PHP_Projects/ Chapter.08/Projects/GuestBook.html. Test the form to see if you can add your name to the database.

  5. Close your Web browser window.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

if you have any doubts please comment:-

Code:

GuestBook.html:-

SignGuestBook.php:-

<!DOCTYPE html> chtml> thead> <title>sign Guest Bookk/title» </head> cbody> <?php if (empty ($ POST[first name]) II empty (echo xp>Unable to create the table.</p> <p>Error codemysql_errno (SDBConnect).:mysql_error (SDBConnect) Jelset SLastName s

output:-

Enter your name to sign our guest book First Name Last Name Submit

phpMyAdmin . cdcol (1) . guestbook (1) information schema (28) . mysql (23)

countlD last_name first_name 1 user name

Add a comment
Know the answer?
Add Answer to:
PHP Programming In this project, you will create a Web page that allows visitors to your...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I am having an issue. When i press submit to test the code, it goes to...

    I am having an issue. When i press submit to test the code, it goes to a blank screen. Please, will some one assist me? Thanks! <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Sign Guest Book</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> </head> <body> <?php if (empty($_POST['?rst_name']) || empty($_POST['last_name']))     echo "<p>You must enter your ?rst and last name! Click your browser's Back button to return to the Guest Book form.</p>"; else {     $DBConnect = @mysql_connect("localhost", "root", "");    ...

  • PHP Programming with MySQL - Why do I get the following error and how do I...

    PHP Programming with MySQL - Why do I get the following error and how do I connect to my database. Looks like I might need to use mysqli instead of mysql but I dont know how to do that or what to change. I appreciate it is you fixed anything that needs to be re-written. Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /Applications/XAMPP/xamppfiles/htdocs/Week9/VerifyLogin.php:12 Stack trace: #0 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/Week9/VerifyLogin.php on line 12 Line 12: $DBConnect =...

  • Need a PHP code that has a box to type in that allows the user to...

    Need a PHP code that has a box to type in that allows the user to put the information through the PHP site to the database for the following categories: INT, First name, Last name, Sex. Once injected it needs to echo to the page to show the table of all entries. The code below is how far I got with it. MySQL: add a row and query $link = mysql_connect('stewcraw.dotstermysql.com', 'prof', '3632password'); if (!$link) { die('Could not connect: '...

  • My 2nd Try asking the same "PHP Programming with MySQL question. When I run my code,...

    My 2nd Try asking the same "PHP Programming with MySQL question. When I run my code, I get the following messages: Notice: Undefined index: email in /Applications/XAMPP/xamppfiles/htdocs/Week9/VerifyLogin.php on line 71 Notice: Undefined index: password in /Applications/XAMPP/xamppfiles/htdocs/Week9/VerifyLogin.php on line 71 Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in /Applications/XAMPP/xamppfiles/htdocs/Week9/VerifyLogin.php on line 75 The e-mail address/password combination entered is not valid. Please use your browser's BACK button to return to the form and fix the errors indicated. Please use...

  • Create web pages for your database using PHP. You should have one page that will return...

    Create web pages for your database using PHP. You should have one page that will return all the information from the database. You should create additional pages that will allow you to do various queries of your database. You should be able to retrieve and insert data; also include functionality to delete data from your database. Create an html form that will allow you to enter in new information for the database. The information should be handled by a PHP...

  • Create an HTML5 page that contains a form to collect the following data. The text in...

    Create an HTML5 page that contains a form to collect the following data. The text in bold indicates the id value that should be assigned to each html control: Product (drop down list) product – iPad, iPhone 6S, Galaxy 5S, Moto X, and so on Quantity (number) quantity Unit price (number) unit_price Discount (%)(number) discount_rate Date (date)   order_date First Name (text box)   first_name Last Name (text box)   last_name Payment type (drop down list)   payment_type – Visa, Master, Discover, Amex, and...

  • <html> <!--This is the form for an instructor to upload a file having the grade of...

    <html> <!--This is the form for an instructor to upload a file having the grade of students in a class--> <body> <h2>Upload Student Grade</h2> <form action="1.php" method="POST" enctype="multipart/form-data">    Instructor's First Name:<input type="text" name="first"><br><br>    Instructor's Last Name: <input type="text" name="last"><br><br>      Instructor's Department Name:<input type="text" name="department"><br><br>          Upload student grade: <input type="file" name="image" /><br><br> <input type="submit"/> </form>    </body> </html> //***************************************************Q1****************************************************************************      /*(((( Q1)))). (18 points) Add the code below that *   uploads the file containing the students'...

  • In this assignment you will combine HTML, PHP, and SQL in order to create a web...

    In this assignment you will combine HTML, PHP, and SQL in order to create a web form that allows a manager to add films to the sakila database. You will also create a method to allow the manager to view a list of all films along with their related information, and a list of actors in the movies. Task 1 Create an initial HTML page titled manager.html with 2 buttons. The first button will be labeled “View Films”, and the...

  • PHP Programming Question. Use the techniques you learned so far to create an Address Book application...

    PHP Programming Question. Use the techniques you learned so far to create an Address Book application that stores names, e-mail addresses, and phone numbers in a text file. Validate all input fields and include functionality that allows the user to view the address book. Also, include code that sorts the address book by name and deletes duplicate entries. Each page in the application should have a link back to the main page. Be creative and add extra features if you...

  • This is a PHP programming class Create a Web form that shows the mileage between European...

    This is a PHP programming class Create a Web form that shows the mileage between European capitals. Use a two-dimensional associative array to store the mileage. The form should allow the user to enter a start city and an end city. Your code should then search the two dimensional for the distance from each city. For Example: A user enters Berlin to Paris. You should return "The distance from Berlin to Paris is: 879.96 km" Add the following code to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT