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", "");    ...

  • How can I print the Database table in PHP please ? here I have form for name and email, also I have php code that allow...

    How can I print the Database table in PHP please ? here I have form for name and email, also I have php code that allow user to add his name and email to my database, all I need to print my final database when the user click on submit. <form action="" method="post"> <label>Name :</label> <input type="text" name="name" required="required" placeholder="Please Enter Name"/><br /><br /> <label>Email :</label> <input type="email" name="email" required="required" /><br/><br /> <input type="submit" value=" Submit " name="submit"/><br /> </form>...

  • 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: '...

  • LANGUAGE JAVASCRIPT, PHP Need help with PHP and ajax code. The user needs to login but,...

    LANGUAGE JAVASCRIPT, PHP Need help with PHP and ajax code. The user needs to login but, I keep getting an error that I coded "Wrong username and password!" ***PLEASE DONT GIVE ME A NEW CODE THAT IS NOWHERE NEAR THE CODE I SUBMITTED***** PLEASE LOOK AT THE CODE AND SEE ANY ISSUES login.html <!DOCTYPE html> <html> <head> <title>login popup</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <style type="text/css"> body { background-color: white; } </style> </head> <body> <center> <h1 style="text-align: center;"> Login </h1> <form>             Login ID:...

  • Write a PHP script that obtains a URL and its description from user and stores the...

    Write a PHP script that obtains a URL and its description from user and stores the information into a database using MySQL. Create and run a SQL script with database named URL and a table named Urltable. The first field of the table should contain an actual URL, and the second, which is named Description, should contain a description of the URL. Use www.deitel.com as the first URL, and input Cool site! as its description. The second URL should be...

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

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

  • For this code below, I need to add the form information to mysql when I click...

    For this code below, I need to add the form information to mysql when I click on submit, at the same time when I click on submit I need to move to another page like Welcome.php WITH NOTE THAT THE ENTERED INFORMATION NOW ALREADY IN DATABASE how can I male that with my code below? THANKS ................................................................................................................................................   <form method="POST"> <div class="container">    <label for="fname"><b>First Name</b></label> <input type="text" placeholder="Enter First Name" name="fname" required> <label for="lname"><b>Last Name</b></label> <input type="text" placeholder="Enter Last Name"...

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

  • URGENT HELP NEEDED: JQuery. PLEASE POST SCREEN SHOTS Task 1: Downloading jQuery Right-click the link to...

    URGENT HELP NEEDED: JQuery. PLEASE POST SCREEN SHOTS Task 1: Downloading jQuery Right-click the link to download the uncompressed latest version of jQuery Copy the jQuery.x.x.x.js file in the folder and specified as source file. Task 2: Download and install HTML-Kit 1. Navigate to htmlkit.com. 2. Click Download HTML-Kit 292. After it downloads, launch HKSetup.exe. Choose Full installation (the default) Uncheck Yes, download and install HTML-Kit Tools Trial. 6. Click Next>Finish. Task 3: Creating a Simple jQuery Application Launch HTML-Kit....

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
ADVERTISEMENT