} upon successful update * - { "error" : } if an error occurs (see below) * * Invalid Request (400) Errors (in order of precedence): * - Missing required name parameter * - No menu item found with given name parameter * * Service Unavailable (503) Error when a DB connection occurs */ include "common.php"; if (isset($_POST["name"])) { $name = $_POST["name"]; $db = get_PDO(); if (!find_item($db, $name)) { # find_item is used by other PHP programs, so we factor in common.php # error if trying to delete an item already on the menu handle_request_error("No item on the menu found with name: {$name}"); } else { remove_item($db, $name); } } else { handle_request_error("Missing required name parameter"); } /** * Removes the item with the given name from the menu, if it exists. * Outputs a JSON response with a success message upon successful removal, otherwise a * descriptive error message (see web service documentation for possible errors). * * @param {PDO} $db - PDO object connected to cafedb * @param $name {string} - name for removed items (case-insensitive in MySQL!) */ function remove_item($db, $name) { $qry = "DELETE FROM menu WHERE name=:name"; try { $stmt = $db->prepare($qry); $params = array("name" => $name); $stmt->execute($params); } catch (PDOException $ex) { handle_db_error(); } output_success("{$name} removed from the menu!"); } ?>