setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $stmt = $pdo->prepare("SELECT * FROM `cms_card`"); $stmt->execute(); $cards = $stmt->fetchAll(PDO::FETCH_ASSOC); function strStartsWith(string $needle, string $haystack) { return substr($haystack, 0, strlen($needle)) === $needle; } if (isset($_GET["editType"])) { $type = explode('!', $_GET["editType"]); if ($type[0] === "Add" || $type[0] === "Edit") { if ($type[0] === "Edit") { $stmt = $pdo->prepare("SELECT * FROM `cms_card` WHERE `id` = :id"); $stmt->execute(["id" => $type[1]]); $card = $stmt->fetchAll(PDO::FETCH_ASSOC)[0]; } else { $card = [ "title" => "", "body" => "", ]; } $_SESSION["edited_card"] = $card; header("Location: cardEdit.php"); } elseif ($type[0] === "Remove") { $stmt = $pdo->prepare("DELETE FROM `cms_card` WHERE `id` = :id"); $stmt->execute(["id" => $type[1]]); $card = $stmt->fetchAll(PDO::FETCH_ASSOC); header("Location: cardsList.php"); } exit(); } ?>
| Id | Title | Body | Edit |
|---|---|---|---|
| {$card["id"]} | $title | $body | Edit Remove |