duancheng3342 2013-11-03 13:01
浏览 9

我的更新查询无法在Codeigniter上运行

I have a table name "Category" which contains (cat_id, name, description). I can insert, retrieve, and delete without any problems. But when I update my Category, no data inserted in my database. I check my table and the result is nothing.

The POST model "Category_Model extends CI_Model":

public function custom_query($data)
    {
        $q = $this->db->query($data);
        return $q;
    }

The POST controller "Category extends CI_Controller":

public function edit_category()
    {
        $data['title'] = "Edit Category Page";

        $this->load->view('edit_category', $data);
    }

    public function update_category()
    {
        $id = $this->input->post('cat_id'); // I try $id = $this->uri->segment(3); but no result
        $name = $this->input->post('name');
        $desc = $this->input->post('description');

        $this->post_model->custom_query("update category set cat_name='".$name."', description='".$desc."' where cat_id='".$id."'"); // when I delete 'where cat_id='".$id."'' clause, all my records were changing/updating
        // I change to $this->db->where('cat_id', $id); $this->db->update('category'), but no result.

        redirect ('category/view_categories');
    }

Here is my EDIT CATEGORY view:

<form action="<?php echo base_url(); ?>category/update_category" method="POST">
            <fieldset>
                <legend>Edit Category</legend>
                <label for="cat">Name :</label>
                <input type="text" name="name"/>
                <label for="desc">Descriptions :</label>
                <textarea name="description" cols="40" rows="2"></textarea>
                <input type="submit" value="Update">
            </fieldset>
        </form>

Please anyone tell me what was wrong with my code? Thank in advance

best regards.

*note: I put 'database' in autoload config.

  • 写回答

4条回答 默认 最新

  • 普通网友 2013-11-03 13:38
    关注

    First of all, are you sure you writing table name correctly?

    ..."update kategori..."
    

    If this is ok, try to output your query before sending it to database, like this:

    $query = "update kategori set cat_name='".$name."', description='".$desc."' where cat_id='".$id."'";
    error_log('My query: ' . print_r($query, true));
    $this->post_model->custom_query($query);
    

    Then, if you won't see any problems in that query, give it to us.

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?