public function updateCategory($status, $main_category, $title, $bg_color, $meta_title, $meta_description, $meta_keywords, $id)
{
$sql = "UPDATE categories SET status = ?, main_category = ? , title = ?, bg_color = ?, meta_title = ?, meta_description = ?, meta_keywords = ? WHERE id = ?";
$stmt = $this->conn->prepare($sql);
try {
$stmt->execute([$status, $main_category, $title, $bg_color, $meta_title, $meta_description, $meta_keywords, $id]);
return true;
} catch (Exception $e) {
echo $e->getMessage();
return false;
}
}
表格发布区域
$category = new Categories(); $id = $_GET['id']; $query = $category->getCategoryDetails($id); $result = false; if (isset($_POST['categorySave'])) { $result = $category->updateCategory($_POST['status'],$_POST['main_category'],$_POST['title'],$_POST['bg_color'],$_POST['meta_title'],$_POST['meta_description'], $_POST['meta_keywords'], $query->id); } ?> <form action="<?=$_SERVER['REQUEST_URI'];?>" method="post" enctype="multipart/form-data"> <?php if ($result) { ?> <div class="alert alert-success" role="alert"> <?=UPDATESUCCESS?> </div> <?php } ?> <label for="title">Başlık</label> <input type="text" class="form-control" id="title" name="title" placeholder="Başlık" value="<?=$query->title?>"> ...
其更新数据没有问题。例如,如果我更改标题“ Title New”,它将在数据库上更新。但是在表单提交后,它保持不变。 “旧标题”
$result = false;
if (isset($_POST['categorySave'])) {
$result = $category->updateCategory($_POST['status'],$_POST['main_category'],$_POST['title'],$_POST['bg_color'],$_POST['meta_title'],$_POST['meta_description'], $_POST['meta_keywords'], $query->id);
}
$category = new Categories();
$id = $_GET['id'];
$query = $category->getCategoryDetails($id);
?>
<form action="<?=$_SERVER['REQUEST_URI'];?>" method="post" enctype="multipart/form-data">
<?php if ($result) { ?>
<div class="alert alert-success" role="alert">
<?=UPDATESUCCESS?>
</div>
<?php } ?>
<label for="title">Başlık</label>
<input type="text" class="form-control" id="title" name="title" placeholder="Başlık" value="<?=$query->title?>">
...