$result = $mainCategory->getIdCategory(); $cat_id = $result['id']; $subCategory = new SubCategory(); $subCategory->category_id = $cat_id; $data = $subCategory->getSubCatByMainCat(); echo json_encode($data); break; case 'addProduct': # code... $mainCategory = new MainCategory(); $mainCategory->type = $_POST['typeMain']; $result = $mainCategory->getIdCategory(); $cat_id = $result['id']; $subCategory = new SubCategory(); $subCategory->category_id = $cat_id; $subCategory->type = $_POST['typeSub']; $res = $subCategory->getSubCatId(); $idSub = $res['id']; $product = new Product(); $product->sub_id = $idSub; $product->material = $_POST['material']; $product->qty = $_POST['qty']; $product->price = $_POST['price']; $product->color = $_POST['color']; $product->size = $_POST['size']; echo $product->insertProduct(); break; default: # code... break; }