46 lines
1.1 KiB
PHP
46 lines
1.1 KiB
PHP
<?php
|
|
require_once 'config.php';
|
|
require_once FOLDER_ROOT.'/lib/Database/DbMessage.php';
|
|
use MessageBoard\Database\DbMessage;
|
|
$db = new DbMessage();
|
|
|
|
// 刪除資料
|
|
if (!empty($_POST["id"]) && !empty($_POST["delete"]) && $_POST["delete"] == "true") {
|
|
$id = $_POST["id"];
|
|
// 修改成功
|
|
if ($db->delete($id)) {
|
|
header('Location: index.php');
|
|
}
|
|
// 修改失敗
|
|
else {
|
|
header('Location: edit.php?id='.$id);
|
|
}
|
|
}
|
|
// 修改資料
|
|
elseif (!empty($_POST['id'])) {
|
|
$id = $_POST['id'];
|
|
$title = $_POST['title'];
|
|
$content = nl2br($_POST['content']);
|
|
// 修改成功
|
|
if ($db->edit($id, $title, $content)) {
|
|
header('Location: view.php?id='.$id);
|
|
}
|
|
// 修改失敗
|
|
else {
|
|
header('Location: edit.php?id='.$id);
|
|
}
|
|
}
|
|
// 新增資料
|
|
else {
|
|
$title = $_POST['title'];
|
|
$content = nl2br($_POST['content']);
|
|
// 修改成功
|
|
if ($id = $db->insert($title, $content)) {
|
|
header('Location: view.php?id='.$id);
|
|
}
|
|
// 修改失敗
|
|
else {
|
|
header('Location: edit.php');
|
|
}
|
|
}
|