Question: So I will post the 3 PHP files so you can hopefully see what I'm talking about. index.php file product_list.php file Product List Categories Code

 So I will post the 3 PHP files so you can

So I will post the 3 PHP files so you can hopefully see what I'm talking about.

index.php file

$action = filter_input(INPUT_POST, 'action'); if ($action == NULL) { $action = filter_input(INPUT_GET, 'action'); if ($action == NULL) { $action = 'list_products'; } }

if ($action == 'list_products') { $category_id = filter_input(INPUT_GET, 'category_id', FILTER_VALIDATE_INT); if ($category_id == NULL || $category_id == FALSE) { $category_id = 1; } $category_name = get_category_name($category_id); $categories = get_categories(); $products = get_products_by_category($category_id); include('product_list.php'); } else if ($action == 'delete_product') { $product_id = filter_input(INPUT_POST, 'product_id', FILTER_VALIDATE_INT); $category_id = filter_input(INPUT_POST, 'category_id', FILTER_VALIDATE_INT); if ($category_id == NULL || $category_id == FALSE || $product_id == NULL || $product_id == FALSE) { $error = "Missing or incorrect product id or category id."; include('../errors/error.php'); } else { delete_product($product_id); header("Location: .?category_id=$category_id"); } } else if ($action == 'show_add_form') { $categories = get_categories(); include('product_add.php'); } else if ($action == 'add_product') { $category_id = filter_input(INPUT_POST, 'category_id', FILTER_VALIDATE_INT); $code = filter_input(INPUT_POST, 'code'); $name = filter_input(INPUT_POST, 'name'); $price = filter_input(INPUT_POST, 'price'); if ($category_id == NULL || $category_id == FALSE || $code == NULL || $name == NULL || $price == NULL || $price == FALSE) { $error = "Invalid product data. Check all fields and try again."; include('../errors/error.php'); } else { add_product($category_id, $code, $name, $price); header("Location: .?category_id=$category_id"); } } else if ($action == 'list_categories') { $categories = get_categories(); include('category_list.php'); } else if ($action == 'add_category') { $name = filter_input(INPUT_POST, 'name');

// Validate inputs if ($name == NULL) { $error = "Invalid category name. Check name and try again."; include('view/error.php'); } else { add_category($name); header('Location: .?action=list_categories'); // display the Category List page } } else if ($action == 'delete_category') { $category_id = filter_input(INPUT_POST, 'category_id', FILTER_VALIDATE_INT); delete_category($category_id); header('Location: .?action=list_categories'); // display the Category List page } ?>

product_list.php file

Product List

Code Name Price

Add Product

List Categories

product_add.php file

Add Product

View Product List

- Start from the solution for exercise 5-1. - In the Product Manager application, add another column to the Product List table that contains Edit buttons. These buttons should link to an Edit Product page that is like the Add Product page, but this page should contain the data for the selected product and have an Update Product button below the text boxes. When this button is clicked, the product should be updated. - To keep things simple, display the category ID in a text box. For extra credit, use a drop-down list to display the correct category name for the product that's being edited. - To learn how to code an UPDATE statement that updates multiple columns, see chapter 18

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!