我正在使用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');
}
感谢任何帮助,谢谢
答案 0 :(得分:2)
就像这样做
$this->db->delete('categories', array('id' => $id));
你也可以把它写成:
$this->db->where('id', $id);
$this->db->delete('categories');
仅用于插入或更新的$data
数组,用于删除您只需使用例如问题行的id