"; //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 = filter_input(INPUT_POST, 'product_id', FILTER_VALIDATE_INT); $category_id = filter_input(INPUT_POST, 'category_id', FILTER_VALIDATE_INT); // Delete the product delete_product($product_id); // // 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 = 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', FILTER_VALIDATE_FLOAT); 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"); } } ?>