"; //step 2 comment out // Get product and category data $category_name = get_category_name($category_id); /******************************************* * step 2: - get all category names * step 2: - get all product names *******************************************/ $categories = get_categories(); $products = get_products_by_category($category_id); // Display the product list include('product_list.php'); // echo $category_name."
"; //step 2 comment out /***************************************** * step 3: action is delete_product ? *****************************************/ } 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); //update model/product_db.php // Display the Product List page for the current category header("Location: .?category_id=$category_id"); /***************************************** * step 4: action is show_add_form ? *****************************************/ } else if ($action == 'show_add_form') { $categories = get_categories(); //created in step 2, model/category_db.php, used for dropdown list include('product_add.php'); //create in product_manager folder /***************************************** * step 5: action is add_product ? *****************************************/ } 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"); } } ?>