Zero (0 ) Database Result in Codeigniter

强颜欢笑 提交于 2019-12-25 08:46:23

问题


In view->new_entry.php

 <?=form_open(base_url().'home/insert_entry/')?>
    <p>Title: <?=form_input('title')?></p>
    <p>Content: <?=form_textarea('content')?></p>
    <p>Tags: <?=form_input('tags')?> (comma separated)</p>
    <?=form_submit('submit', 'Insert')?>

In home/insert_entry:

public function insert_entry(){
        login_site();
        $entry = array(
            'permalink'  => permalink($this->input->post('title')),
            'author' => $this->session->userdata('username'),
            'title' => $this->input->post('title'),
            'content' => $this->input->post('content'),
            'date' => date('Y-m-d H:i:s'),
            'tags' => $this->input->post('tags')
            );      
        $this->home_model->insert('ads', $entry);

        redirect(base_url());
    }

In home_model:

public function insert($table, $data){
        return $this->db->insert($table, $data);
    }

I am getting all result zero (0) on database.


回答1:


Try checking the affected_rows if it is >= 1

public function insert($table, $data){
  $this->db->insert($table, $data);
  return $this->db->affected_rows() >= 1 ? TRUE : FALSE;
}



回答2:


Enable profiler in your controller. eg:

$this->output->enable_profiler(TRUE); 

See if your query is executed and if it's correct...



来源:https://stackoverflow.com/questions/23858441/zero-0-database-result-in-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!