繁体   English   中英

我试图以这种方式将数据更新到数据库中,但是对于第一个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'; 

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

如果要检查方法和值,则应像下面那样测试帖子。

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM