$data = array("status" => "success", "msg" => "Cart cancelled."); } else { $data = array("status" => "fail", "msg" => "Cart NOT cancelled."); } break; case "checkoutcart": // check out the cart if (!isset($_SESSION['started'])) { $data = array("status" => "fail", "msg" => "There is no cart to check out."); echo json_encode($data, JSON_FORCE_OBJECT); return; } // turn the JSON into an array of arrays (true means arrays and not objects) $items = json_decode($_POST['items'], true); $total = $_POST['total']; $scm->addItemsToCart($items, $_SESSION['id']); $affectRows = $scm->checkoutCart($_SESSION['id'], $total); $pm->updateProductStock($items); if ($affectRows > 0) { session_unset(); session_destroy(); $data = array("status" => "success", "msg" => "Cart successfully checked out."); } else { $data = array("status" => "fail", "msg" => "Cart was NOT checked out."); } break; } } else { $data = array("status" => "error", "msg" => "Only POST allowed."); } echo json_encode($data, JSON_FORCE_OBJECT);