A+ Work

 Lab 7 NB: The database management system installed on the weblab server is MariaDB, which uses the MySQL calls; you will need to use mysqli_ API functions for this assignment. Just follow the examples in the link that’s in Part 1 and you’ll be OK. Part 1; From databases to forms: Read Database Access with PHP. Copy your form from Lab Exercise6 to l7p1.php and change it to read the states from a database table instead of putting them into a PHP array yourself. The database is named weblab and the table of states is named state_t. The table was created as follows: CREATE TABLE state_t ( state_abbr char(2) PRIMARY KEY, state_name char(20), state_zone integer); Display the state name in the drop-down, but transmit the state abbreviation through the form. You do this by using a value attribute on the element. The form area for State will look something like the following. Of course, you have to build this using PHP, and not just type it in. <select name=”x_x_x_state”> <option value=”AL”>Alabama</option> <option value=”FL”> Florida</option> <option value=”GA”>Georgia</option> <option value=”TN”>Tennessee </option> </select> You will not use the state_zone attribute. In “real life” it would be used for calculating shipping, maybe. Present the state names in alphabetical order on your form. The easy way to do this is to have the database management system sort them for you using an ORDER BY clause in your SQL. For those of you who took Database long ago and far away (or not at all!), a suitable query for populating the array is this: SELECT state_abbr, state_name from state_t ORDER BY state_name; Make a link to this program from your index page. Part 2, More databases to forms: The database weblab has a table of of fruits named fruit_t. The table was created as follows: CREATE TABLE fruit_t ( fruit_item_no char(10) PRIMARY KEY, fruit_name char(20), fruit_price numeric(6, 2), fruit_weight numeric(4, 1), fruit_picture char(30), fruit_description varchar); Change your fruit order form to construct the table of names, prices and weights by extracting the items from the database rather than hard-coding them. Display every item from the database. Do not assume that you know the number of items. In the database table definition above, numeric(6, 2) means the item has a total of six digits, of which two are to the right of the decimal point. Your order form should display the following items for each kind of fruit: Name Price Shipping Weight You will not need the fruit_picture or fruit_description attributes. Your form should leave a text box to allow the customer to enter quantity as you did in earlier assignments. Present the fruit names in alphabetical order. The following is a suitable query for retrieving from the database: select fruit_item_no, fruit_name, fruit_price, fruit_weight from fruit_t order by fruit_name; This is a modification of l7p1.php, and I will test it when I test Part 1. Your program will still be named l7p1.php. Your order form should display the following items for each item: Name Price Shipping Weight Note: This change will “break” your JavaScript validation routines if you still have them in your form. In real life, you would have to fix this. However, in real life, you would have started with the database-driven form, so you would not have to back-track. You do not have to change your validation routines, but see Part 4 below. Part 3; Thinking about database items: Answer the following question: The query you were given in Part 2 retrieved the fruit_item_no attribute from the database. Did you do anything with it? Why, or why not? Hint: Is it remotely possible that two different kinds of fruits may have the same name? Another hint: See Part 4. Put your answer on a Web page, l7p3.html and make a link to it from your index page. Part 4; Thinking about form data validation: Explain in no more than a paragraph each what you would have to do with your JavaScript validation to make it work with the database-driven order form.