<?php require "../includes/include.php"; if (is_numeric($_POST["id"]) && intval($_POST["id"]) > 0) { $sqlite = new SQLite3($db_str, SQLITE3_OPEN_READWRITE); $id = intval($_POST["id"]); $link = findLinkById($id); $delete = $sqlite->prepare("delete from links where l_id=:id"); $delete->bindValue("id", $id, SQLITE3_INTEGER); if ($delete->execute() !== false) { $result = ["delete" => $link, "success" => true, "message" => date("Y-m-d H:i:s"), "anchor" => "s" . $link["section"]]; } else { $result = ["delete" => $link, "success" => false, "message" => "Unable to execute query", "anchor" => "s" . $link["section"]]; } $delete->close(); $sqlite->close(); } else { $result = ["delete" => $_POST["id"], "success" => false, "message" => "Bad request"]; } print json_encode($result);
<?php require "../includes/include.php"; if (!empty($_POST["url"]) && is_numeric($_POST["section"]) && intval($_POST["section"]) > 0) { $sqlite = new SQLite3($db_str, SQLITE3_OPEN_READWRITE); $url = $_POST["url"]; $comment = $_POST["comment"]; $section = is_numeric($_POST["section"]) && intval($_POST["section"]) > 0 ? intval($_POST["section"]) : null; if (sectionExists($section)) { $insert = $sqlite->prepare("insert into links (l_url,l_comment,l_section) values (:url,:comment,:section)"); $insert->bindValue("url", $url, SQLITE3_TEXT); $insert->bindValue("comment", $comment, SQLITE3_TEXT); $insert->bindValue("section", $section, SQLITE3_INTEGER); if ($insert->execute() !== false) { $id = $sqlite->querySingle("select l_id from links where rowid=" . $sqlite->lastInsertRowId()); $result = ["insert" => findLinkById($id), "success" => true, "message" => date("Y-m-d H:i:s"), "anchor" => "s{$section}"]; } else { $result = ["insert" => ["url" => $url, "comment" => $comment, "section" => $section], "success" => false, "message" => "Unable to execute query", "anchor" => "s{$section}"]; } $insert->close(); } else { $result = ["insert" => ["url" => $url, "comment" => $comment, "section" => $section], "success" => false, "message" => "Section {$section} not found"]; } $sqlite->close(); } else { $result = ["insert" => $_POST, "success" => false, "message" => "Bad request"]; } print json_encode($result);
require "../includes/include.php"; if (is_numeric($_POST["id"]) && intval($_POST["id"]) > 0 && !empty($_POST["url"]) && is_numeric($_POST["section"]) && intval($_POST["section"]) > 0) { $sqlite = new SQLite3($db_str, SQLITE3_OPEN_READWRITE); $id = intval($_POST["id"]); $url = $_POST["url"]; $comment = $_POST["comment"]; $section = intval($_POST["section"]); $link = findLinkById($id); if ($link !== false && sectionExists($section)) { $update = $sqlite->prepare("update links set l_url=:url,l_comment=:comment,l_section=:section,l_updated=current_timestamp,l_accessed=current_timestamp where l_id=:id"); $update->bindValue("id", $id, SQLITE3_INTEGER); $update->bindValue("url", $url, SQLITE3_TEXT); $update->bindValue("comment", $comment, SQLITE3_TEXT); $update->bindValue("section", $section, SQLITE3_INTEGER); if ($update->execute() !== false) { $result = ["update" => $link, "success" => true, "message" => date("Y-m-d H:i:s"), "target" => findLinkById($id), "anchor" => "s" . $link["section"]]; } else { $result = ["update" => $link, "success" => false, "message" => "Unable to execute query", "target" => ["url" => $url, "comment" => $comment, "section" => $section], "anchor" => "s" . $link["section"]]; } $update->close(); } else { $result = ["success" => false, "target" => ["url" => $url, "comment" => $comment, "section" => $section]]; if ($link === false) { $result["update"] = id; $result["message"] = "Identifier {$id} not found"; } else { $result["update"] = $link; $result["message"] = "Section {$section} not found"; $result["anchor"] = "s" . ($link["section"] != null ? $link["section"] : "null"); } }