编辑失败说成功但有任何错误

问题描述 投票:0回答:1

更新成功但出现错误

<br /><b>Warning</b>:  Undefined variable $topic in <b>C:\xampp\htdocs\mintech\templates\editcat.php</b> on line <b>13</b><br /><br /><b>Warning</b>:  Attempt to read property 
警告:第10线上
C:\xampp\htdocs\mintech ditcat.php

中未定义数组键“cat_id”

很抱歉我是 php oop mvc 结构的新手 我尝试将 id 传递到 action=editcat.php 中,但没有 我也尝试过输入隐藏来传递 cat_id 仍然没有 我尝试声明一个变量主题什么都没有 我尝试在不更新任何内容时更改占位符

  public function update_Cat($data){
    //Insert Query
    $this->db->query("UPDATE `categories` SET name=:name Where cat_id = :cat_id ");
    //Bind Values
    $this->db->bind(':name', $data['name']);
    $this->db->bind(':cat_id', $data['cat_id']);
    if($this->db->execute()){
      return true;
    } else {
      return false;
    }
    //echo $this->db->lastInsertid
  }
<?php
//Create Topics Object
$topic = new Topic;
$user = new User;
$validate = new Validator;

//Get Template From URL
$categories_id = $_GET['cat_id'];


if (isset($_POST['edit_cat'])) {
    //Creatr Data array
    $data = array();
    $data['name'] = $_POST['name'];
//required array
$field_array = array('name');
if ($validate->isRequired($field_array)) {
    //Register User
    if ($topic->update_Cat($data)) {
        redirect('editcat.php', 'your Category has been updated', 'success');
    } else {
        redirect('editcat.php', 'Something went wrong with your Update', 'error');
    }
    } else {
        redirect('editcat.php',  'Name field is required',  'error');
    }
}
php pdo updating
1个回答
-1
投票

似乎当我传递 id 时,它没有被传递,所以我更改了在表单中传递 id 的方法,还添加了隐藏的输入并传递了 id 并在 editcat.php 上声明了它,然后它工作了哇谢谢团队

你真的打开了我的心扉

© www.soinside.com 2019 - 2024. All rights reserved.