PHP在表单提交后仍然给我旧数据

PHP在表单提交后仍然给我旧数据,php,mysql,pdo,Php,Mysql,Pdo,我有一张表格,用来更新我的分类表上的一些数据。在我通过表单发布新数据后,页面会刷新,但它仍然会向我显示旧数据 public function updateCategory($status, $main_category, $title, $bg_color, $meta_title, $meta_description, $meta_keywords, $id) { $sql = "UPDATE categories SET status = ?, main_category = ? ,

我有一张表格,用来更新我的分类表上的一些数据。在我通过表单发布新数据后,页面会刷新,但它仍然会向我显示旧数据

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?>">
        ...
$category=新类别();
$id=$_GET['id'];
$query=$category->getCategoryDetails($id);
$result=false;
如果(isset($_POST['categorySave'])){
$result=$category->updateCategory($\u POST['status'],$\u POST['main\u category'],$\u POST['title'],$\u POST['bg\u color'],$\u POST['meta\u title'],$\u POST['meta\u description'],$\u POST['meta\u关键字'],$query->id);
}
?>

将更新代码移到get代码上方

$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?>">
        ...
$result=false;
如果(isset($_POST['categorySave'])){
$result=$category->updateCategory($\u POST['status'],$\u POST['main\u category'],$\u POST['title'],$\u POST['bg\u color'],$\u POST['meta\u title'],$\u POST['meta\u description'],$\u POST['meta\u关键字'],$query->id);
}
$category=新类别();
$id=$_GET['id'];
$query=$category->getCategoryDetails($id);
?>

如果在执行更新后获取CategoryDetail,您将看到新数据。按照现在的方式,您可以获取所有旧数据。。。运行更新。。。并且显示您选择的旧日期。除非您在某个地方定义了
更新成功
,否则不确定该日期的作用