【问题标题】:Deleting content in Codeigniter删除 Codeigniter 中的内容
【发布时间】:2017-05-28 01:05:38
【问题描述】:

我正在使用 Codeigniter 构建博客,但在删除类别时遇到了问题。我可以创建它们,编辑它们,但我不能删除它们。我收到此错误:

遇到了 PHP 错误

严重性:通知

消息:未定义变量:数据

文件名:models/article_model.php

行号:167

回溯:

文件:F:\wamp64\www\site\application\models\article_model.php 行: 167 函数:_error_handler

文件:F:\wamp64\www\site\application\controllers\admin\categories.php 行:85 功能:delete_category

文件:F:\wamp64\www\site\index.php 行:315 功能:require_once

A Database Error Occurred

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IS NULL' at line 3

DELETE FROM `categories` WHERE `id` = '5' AND IS NULL

Filename: F:/wamp64/www/site/system/database/DB_driver.php

Line Number: 691

我正在使用 PHP7 和 CodeIngiter 3.1.3

这是我的 article_model.php 中的代码

public function delete_category($id){
    $this->db->where('id', $id);
    $this->db->delete('categories', $data); // this is line 167
    return true;
}

这是来自 categories.php 的代码

public function delete($id){
    $this->Article_model->delete_category($id); // this is line 85

    //Create Message
    $this->session->set_flashdata('category_deleted', 'Your category has been deleted');

    //Redirect to articles
    redirect('admin/categories');
}

感谢任何帮助,谢谢

【问题讨论】:

    标签: php codeigniter


    【解决方案1】:

    就这样吧

    $this->db->delete('categories', array('id' => $id)); 
    

    你也可以这样写:

    $this->db->where('id', $id);
    $this->db->delete('categories');
    

    $data 数组仅用于插入或更新,删除您只需使用例如相关行的id

    【讨论】:

      猜你喜欢
      • 2014-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多