2017-01-12 13 views
0

私はCodeigniterでブログを構築していますが、カテゴリの削除に問題があります。私はそれらを作成し、編集することができますが、削除することはできません。私はこのエラーを取得:Codeigniterでコンテンツを削除する

私はPHP7を使用してい

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: data

Filename: models/article_model.php

Line Number: 167

Backtrace:

File: F:\wamp64\www\site\application\models\article_model.php Line: 167 Function: _error_handler

File: F:\wamp64\www\site\application\controllers\admin\categories.php Line: 85 Function: delete_category

File: F:\wamp64\www\site\index.php Line: 315 Function: 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 

と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'); 
} 

$data配列のみが挿入または更新のために必要とされる

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

あなただけの使用を削除するために、:評価され、感謝

答えて

2

は同じようにあなたもそれを書くことができ、この

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

のようにそれを行います例えば問題の行のid

関連する問題