<?php include 'sub-category.php'; if (isset($_GET['id'])) { if ($_GET['value'] == 'Delete') { $sub_category = new subcategory($_GET['id']); $sub_category->delete(); $jsondata = json_encode($sub_category->getallsubcategory()); echo $jsondata; } if ($_GET['value'] == 'Update') { $errors = []; $sub_category = new subcategory($_GET['id']); if (empty(trim($_GET['name']))) { $errors[] = "the name is empty"; $_SESSION['errors'] = $errors; } if ($sub_category->subcategory_is_exist($_GET['cat'], $_GET['name'])) { $errors[] = "the subcategory is already exist"; $_SESSION['errors'] = $errors; } if (empty(trim($_GET['desc']))) { $errors[] = "the desc is empty"; $_SESSION['errors'] = $errors; } if (!empty($errors)) { $errors[] = $_GET["id"]; } else { $sub_category->sub_cat_name = $_GET['name']; $sub_category->sub_cat_desc = $_GET['desc']; $sub_category->cat_id = $_GET['cat'];
<?php include 'subcategoryclass.php'; if (isset($_GET['id']) && is_numeric($_GET['id'])) { // get the 'id' variable from the URL $id = $_GET['id']; $scateg = new subcategory(); $scateg->delete($id); header("location:addSubcategory.php"); } else { header("location:addSubcategory.php"); }