From 46479a9353a044eee97aa1904cd8348d48b88455 Mon Sep 17 00:00:00 2001 From: Yuan Chiu Date: Thu, 9 Apr 2020 21:28:10 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/index.php | 2 +- htdocs/lib/Database/DbMessage.php | 6 +++++- htdocs/save.php | 19 +++++++++++++++---- htdocs/view.php | 2 +- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/htdocs/index.php b/htdocs/index.php index f87bdd0..2c5aca1 100644 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -64,7 +64,7 @@ $list = $db->getList(); diff --git a/htdocs/lib/Database/DbMessage.php b/htdocs/lib/Database/DbMessage.php index dca4293..4186ed8 100644 --- a/htdocs/lib/Database/DbMessage.php +++ b/htdocs/lib/Database/DbMessage.php @@ -85,6 +85,10 @@ class DbMessage extends Database public function delete($id) { - # code... + $sqlString = "DELETE FROM `".$this->table('message')."` WHERE id= :id"; + $query = $this->connDB->prepare($sqlString); + $query->bindParam(":id", $id); + $query->execute(); + return $query->rowCount(); } } \ No newline at end of file diff --git a/htdocs/save.php b/htdocs/save.php index 20ed23d..08067b4 100644 --- a/htdocs/save.php +++ b/htdocs/save.php @@ -1,15 +1,26 @@ delete($id)) { + header('Location: index.php'); + } + // 修改失敗 + else { + header('Location: edit.php?id='.$id); + } +} // 修改資料 -if (!empty($_POST['id'])) { +elseif (!empty($_POST['id'])) { $id = $_POST['id']; + $title = $_POST['title']; + $content = $_POST['content']; // 修改成功 if ($db->edit($id, $title, $content)) { header('Location: view.php?id='.$id); diff --git a/htdocs/view.php b/htdocs/view.php index 4a9f535..e5610e4 100644 --- a/htdocs/view.php +++ b/htdocs/view.php @@ -33,7 +33,7 @@ $created_at = $item['created_at'];