我尝试过用这种方式将数据更新到数据库中,但对于第一个if语句,其中的if(!empty($_POST))可能不起作用


I have tried to update data into database in this way but something maybe not working for the first if statement where if ( !empty($_POST) )

我曾尝试以这种方式将数据更新到数据库中,但第一个if语句可能不起作用,其中if(!empty($_POST))请看此图以清楚地理解

<?php   require_once '../App/start.php';  if ( !empty($_POST) ) {   $id     = $_POST['id'];     $label  = $_POST['label'];  $title  = $_POST['title'];  $slug   = $_POST['slug'];   $body   = $_POST['body'];   $updatePage = $db->prepare("UPDATE pages SET label=:label, title=:title,body =:body, slug=:slug, updated=NOW() WHERE id = :id");    $updatePage->execute([      'id'        => $id,         'label'     => $label,      'title'     => $title,      'body'      => $body,       'slug'      => $slug    ]);     header('Location:' . BASE_URL . '/index.php'); }  if (!isset($_GET['id'])) {    header('Location:' . BASE_URL . '/Admin/list.php');     die(); }  $edit = $db->prepare("SELECT id, label, title, body, slug FROM pages WHERE id = :id"); $edit->execute(['id' => $_GET['id']]); $edits = $edit->fetch(PDO::FETCH_ASSOC);   require_once VIEW_ROOT . '/Admin/edit.php'; 

根据此代码,第一条语句无法将数据更新到数据库

如果您想检查方法和值,您应该像下面这样测试post。

if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset ($_POST ['id']))

否则CCD_ 2就足够了。