gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 21:10:02 25 4
gpt4 key购买 nike

我尝试以这种方式将数据更新到数据库中,但某些内容可能不适用于第一个 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'; 

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

最佳答案

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

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

否则 if ( isset ($_POST ['id']) ) 就足够了。

关于php - 我尝试以这种方式将数据更新到数据库中,但对于第一个 if 语句 if ( !empty($_POST) ) 可能不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36463882/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com