prepare("DELETE FROM ${table} WHERE ${id_name} = ?;"); $stmt -> bind_param("i", $id); $id = validate_input($_POST[$id_name]); if ($stmt -> execute()) { print header("HTTP/1.1 204 Succesfully deleted item in ${table} table."); } else { print header("HTTP/1.1 500 Internal server error ocurred while deleting item in ${table} table"); } } else { print header("HTTP/1.1 400 Missing ${id_name}"); $out = json_encode(err_msg(3)); } $db->close(); return $out; } if (isset($_POST["t"])) { $type = validate_input($_POST["t"]); print match ($type) { "activity" => general_delete("activity", "a_id"), "activity_transaction" => activity_transaction(), "board_member" => general_delete("board_member", "m_id"), "member" => general_delete("member", "m_id"), "product" => general_delete("product", "p_id"), "transaction" => general_delete("transaction", "t_id"), default => header("HTTP/1.1 400 Incorrect table type") }; } else { print header("HTTP/1.1 400 Missing table type"); print json_encode(err_msg(1)); } function activity_transaction() { include("../../../lib/db.php"); $out = ""; if (isset($_POST["a_id"]) && isset($_POST["t_id"])) { $stmt = $db -> prepare("DELETE FROM activity_transaction WHERE a_id = ? and t_id = ?;"); $stmt -> bind_param("ii", $a_id, $t_id); $a_id = validate_input($_POST["a_id"]); $t_id = validate_input($_POST["t_id"]); if ($stmt -> execute()) { print header("HTTP/1.1 204 Succesfully deleted item in activity_transaction table."); } else { print header("HTTP/1.1 500 Internal server error ocurred while deleting item in activity_transaction table"); } } else { $msg = "HTTP/1.1 400 Missing "; if (!isset($_POST["a_id"])) { if (!isset($_POST["t_id"])) { $msg = "a_id and t_id"; } else { $msg = "a_id"; } } else { $msg = "t_id"; } print header($msg); $out = json_encode(err_msg(3)); } $db->close(); return $out; } ?>