删除mysql记录在codeIgniter中不起作用 [英] Delete mysql records is not working in codeIgniter

查看:39
本文介绍了删除mysql记录在codeIgniter中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的控制器功能:

function delete_article($title){

    if ($this->session->userdata('User') && $this->session->userdata('User') == 'admin@example.com') {

        $this->load->model('Article', 'Article', TRUE);
        $this->Article->delete_article_db($title);

        redirect('admin/user_article');
    } else {
        redirect('');
    }
}

这是我删除数据库记录的模型函数:

And this is my model function for deleting the database record:

 function delete_article_db($title) {
    $this->db->where('Title', $title);
    $this->db->delete('article');
}

当我运行此代码时,没有任何内容被删除.但是,代码不会触发任何错误或警告.

When I run this code, nothing gets deleted. However, the code does not fire any errors or warnings.

这是我的 MySQL 表结构:

This is my MySQL table structure:

CREATE TABLE IF NOT EXISTS `article` (
   `Name` text NOT NULL,
   `Email` text NOT NULL,
   `Phone` text NOT NULL,
   `Address` text NOT NULL,
   `Literature` text NOT NULL,
   `Title` text NOT NULL,
   `Submission_Name` text NOT NULL,
   `Additional_Name` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

推荐答案

有点疯狂的猜测,但是看看您的控制器方法和变量名称,我假设您正在传递 title 通过 url,类似

A bit of a wild guess, but looking at your controller method, and the variable names, I'm assuming you're passing the title via url, something like

http://example.com/admin/delete/Title to be deleted

这让我认为您的查询不起作用,因为 url(或其他字符)中的空格与您的数据库中未编码的空格不匹配.

Which leads me to think your query is not working because of encoding of the spaces in the url (or other characters) which won't match the not encoded spaces in your db.

尝试:

function delete_article_db($title) {
    $this->db->where('Title', rawurldecode($title) );
    $this->db->delete('article');
}

这篇关于删除mysql记录在codeIgniter中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆