Code | Name | Price | |
---|---|---|---|
Add Product
List Categories
Modification -
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 Products 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. I want the Edit button to be placed between the Price column and the Delete button column.
2) To keep things simple, display the category ID in a text box instead of a drop-down list.
________________________________________________________________________________
category_list
Name | |
---|---|
List Products
___________________________________________________________________________________________________
product_add
View Product List
__________________________________________________________________________________________________________
product_list
Code | Name | Price | |
---|---|---|---|
Add Product
List Categories
____________________________________________________________________________________
index
if (isset($_POST['action'])) { $action = $_POST['action']; } else if (isset($_GET['action'])) { $action = $_GET['action']; } else { $action = 'list_products'; }
if ($action == 'list_products') { // Get the current category ID $category_id = $_GET['category_id']; if (!isset($category_id)) { $category_id = 1; }
// Get product and category data $category_name = get_category_name($category_id); $categories = get_categories(); $products = get_products_by_category($category_id);
// Display the product list include('product_list.php'); } else if ($action == 'delete_product') { // Get the IDs $product_id = $_POST['product_id']; $category_id = $_POST['category_id'];
// Delete the product delete_product($product_id);
// Display the Product List page for the current category 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 = $_POST['category_id']; $code = $_POST['code']; $name = $_POST['name']; $price = $_POST['price'];
// Validate the inputs if (empty($code) || empty($name) || empty($price)) { $error = "Invalid product data. Check all fields and try again."; include('../errors/error.php'); } else { add_product($category_id, $code, $name, $price);
// Display the Product List page for the current category header("Location: .?category_id=$category_id"); } } else if ($action == 'list_categories') { $categories = get_categories(); include('category_list.php'); } else if ($action == 'add_category') { $name = $_POST['name'];
// Validate inputs if (empty($name)) { $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 = $_POST['category_id']; delete_category($category_id); header('Location: .?action=list_categories'); // display the Category List page } ?>
There are 3 Steps involved in it
See step-by-step solutions with expert insights and AI powered tools for academic success
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started