Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise 4-1 Enhance the Product Manager application This exercise has you enhance the Product Manager application by adding a page that lets you add and

Exercise 4-1 Enhance the Product Manager application

This exercise has you enhance the Product Manager application by adding a page that lets you add and delete categories. Test the Product Manager application

1. Start the Chrome browser and run the application in the ex_starts\ch04_ex1 directory. To do that, you can use this URL: http://localhost/ex_starts/ch04_ex1/ This should display the products for the first category in the database named my_guitar_shop1.

2. View the products in each of the categories.

3. Add a new product to the database. When you add this product, make sure to enter valid values for a product. Then, delete the product you just added from the database.

4. Click on the List Categories link at the bottom of the page. Note that this link leads to a page thats under construction. However, the link back to the Product List page does work.

Add a Category List page In the rest of this exercise, youll add a page that looks like this:

image text in transcribed

5. Open the category_list.php file thats in the directory for this application. It contains some of the headings and a link back to the Product List page.

6. In the category_list.php file, write the code that creates the category table shown above with all of the category names in the first column and Delete buttons in the second column, similar to how the index.php file works. Then, test that this table is displayed correctly.

7. In the category_list.php file, write the code that lets the user add a category to the database. This code should consist of a form that accepts the name for a new category followed by a Submit button that displays Add, similar to how the add_product_form.php file works. Then, test that this form is displayed correctly.

8. Create an add_category.php file that adds a category to the database and a delete_category.php file that deletes a category from the database. These files should display the Category List page after they add or delete a category, similar to how the add_product.php and delete_product.php files work.

9. Test the application by adding two categories. Then, navigate to the Product List page and note that the list of categories includes the new categories. Next, navigate to the Add Product page and note that the drop-down list includes the new categories.

10. Test the application by deleting the categories that you just added. However, dont delete any of the existing categories because that will lead to products without categories. If necessary, though, you can restore the database by running the create_db.sql script again as described in the appendixes.

index.php:

// Get category ID if (!isset($category_id)) { $category_id = filter_input(INPUT_GET, 'category_id', FILTER_VALIDATE_INT); if ($category_id == NULL || $category_id == FALSE) { $category_id = 1; } } // Get name for selected category $queryCategory = 'SELECT * FROM categories WHERE categoryID = :category_id'; $statement1 = $db->prepare($queryCategory); $statement1->bindValue(':category_id', $category_id); $statement1->execute(); $category = $statement1->fetch(); $category_name = $category['categoryName']; $statement1->closeCursor();

// Get all categories $query = 'SELECT * FROM categories ORDER BY categoryID'; $statement = $db->prepare($query); $statement->execute(); $categories = $statement->fetchAll(); $statement->closeCursor();

// Get products for selected category $queryProducts = 'SELECT * FROM products WHERE categoryID = :category_id ORDER BY productID'; $statement3 = $db->prepare($queryProducts); $statement3->bindValue(':category_id', $category_id); $statement3->execute(); $products = $statement3->fetchAll(); $statement3->closeCursor(); ?>

My Guitar Shop

Product Manager

Product List

Code Name Price

Add Product

List Categories

© My Guitar Shop, Inc.

category_list.php:

// Get all categories $query = 'SELECT * FROM categories ORDER BY categoryID'; $statement = $db->prepare($query); $statement->execute(); $categories = $statement->fetchAll(); $statement->closeCursor(); ?>

My Guitar Shop

Product Manager

Category List

Name
echo $category['categoryName']; ?

Add Category

List Products

© My Guitar Shop, Inc.

23 My Guitar Shop localhost/ex_solutions/ch04_exl_sol/category_list.php : Product Manager Category List Name Guitars Delete Delete Basses Drums Delete Add Category Name: Add List Products 2017 My Guitar Shop, Inc. 23 My Guitar Shop localhost/ex_solutions/ch04_exl_sol/category_list.php : Product Manager Category List Name Guitars Delete Delete Basses Drums Delete Add Category Name: Add List Products 2017 My Guitar Shop, Inc

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Next Generation Databases NoSQLand Big Data

Authors: Guy Harrison

1st Edition

1484213300, 978-1484213308

More Books

Students also viewed these Databases questions

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago