简体   繁体   English

Codeigniter / Postgresql:致命错误:在非对象上调用成员函数num_rows()

[英]Codeigniter/Postgresql: Fatal error: Call to a member function num_rows() on a non-object

This thing is been bothering me of a couple of days and I haven't been able to fix it. 这件事困扰了我几天,而我却无法修复它。 I have this registration form. 我有这张注册表。 And when submitting this form This error keeps popping up and the reason for this happening is the registration details are not getting inserted into the database. 提交此表单时,此错误不断弹出,并且发生这种情况的原因是未将注册详细信息插入数据库。

I am using Postgresql as the database system. 我正在使用Postgresql作为数据库系统。 But the data is not getting inserted. 但是没有插入数据。 I am really frustrated with this. 我对此感到非常沮丧。 I will post my model, controller below, If anything is required please let me know. 我将在下面发布我的模型,控制器,如果需要任何信息,请告诉我。

Controller: 控制器:

    function register()
{

    //set validation rules
    $this->form_validation->set_rules('customer_name', 'Customer Name', 'trim|required|xss_clean');
    $this->form_validation->set_rules('address1', 'Address 1', 'trim|required|xss_clean');
    $this->form_validation->set_rules('address2', 'Address 2', 'trim|required|xss_clean');
    $this->form_validation->set_rules('city', 'City', 'trim|required|xss_clean');
    $this->form_validation->set_rules('state', 'State', 'trim|required|xss_clean');
    $this->form_validation->set_rules('country', 'Country', 'trim|required|xss_clean');
    $this->form_validation->set_rules('phone', 'Phone', 'trim|required|xss_clean|is_numeric');
    $this->form_validation->set_rules('mobile', 'Mobile', 'trim|required|xss_clean|is_numeric');
    $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|is_unique[gkb_users.email]');
    $this->form_validation->set_rules('username', 'Username', 'trim|required|is_unique[gkb_users.username]');
    $this->form_validation->set_rules('password', 'Password', 'trim|required|md5');
    $this->form_validation->set_rules('confpassword', 'Confirm Password', 'trim|required|matches[password]|md5');

    //validate form input
    if ($this->form_validation->run() == FALSE)
    {
    //fails
    $this->loadHeader($this);

    //load sidebar
    $this->loadSidebar($this);

    //load middle content
    $this->load->view('register_view'); 

    //load footer
    $this->loadFooter($this);
    }
    else
    {
        //insert the user registration details into database
        $data = array(
            'cust_name' => $this->input->post('customer_name'),
            'address1' => $this->input->post('address1'),
            'address2' => $this->input->post('address2'),
            'city' => $this->input->post('city'),
            'state_code' => $this->input->post('state'),
            'country_code' => $this->input->post('country'),
            'phone' => $this->input->post('phone'),
            'mobile' => $this->input->post('mobile'),
            'email' => $this->input->post('email'),
            'username' => $this->input->post('username'),
            'password' => $this->input->post('password'),
        );

        // insert form data into database
        if ($this->user_model->insertUser($data))
        {
            // send email
            if ($this->user_model->sendEmail($this->input->post('email')))
            {
                // successfully sent mail
                $this->session->set_flashdata('msg','<div class="alert alert-success text-center">You are Successfully Registered! Please confirm the mail sent to your Email-ID!!!</div>');
                redirect('user/register');
            }
            else
            {
                // error
                $this->session->set_flashdata('msg','<div class="alert alert-danger text-center">Oops! Error.  Please try again later!!!</div>');
                redirect('user/register');
            }
        }
        else
        {
            // error
            $this->session->set_flashdata('msg','<div class="alert alert-danger text-center">Oops! Error.  Please try again later!!!</div>');
            redirect('user/register');
        }
    }
}

Model: 模型:

    function insertUser($data)
{
    return $this->db->insert('users', $data);
}

I will be really grateful if I can solve this. 如果能解决这个问题,我将不胜感激。 Thanks 谢谢

EDIT: 编辑:

    public function checkfrontendUser($username,$passwd)
{
    $sql = "
        SELECT * FROM users
        WHERE (
                    `username` = '".$username."'
                    OR
                    `email` = '".$username."'
              )
              AND `password` = '".$passwd."'
    ";      
    $result = $this->db->query($sql);
    if ($result->num_rows() > 0)
    {
        return $result->result_array();
    }       
    return FALSE;
}

Mainly this can happen for database connection problem or your query is failing. 主要是由于数据库连接问题或查询失败而发生的。 No matter how you are connecting your DB whether through database.php or $this->load->database() . 不管如何,你是否是通过连接你的数据库database.php$this->load->database() double check your Db credentials. 仔细检查您的Db凭据。

secondly you may check as 其次,您可以检查为

if($result !== FALSE){
    if ($result->num_rows() > 0){
        return $result->result_array();
    }  
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Codeigniter:致命错误:在非对象上调用成员函数num_rows() - Codeigniter : Fatal error: Call to a member function num_rows() on a non-object 在codeigniter中的非对象上调用成员函数num_rows() - Call to a member function num_rows() on a non-object in codeigniter Codeigniter调用非对象上的成员函数num_rows() - Codeigniter Call to a member function num_rows() on a non-object 致命错误:在非对象上调用成员函数num_rows() - Fatal Error:Call to a member function num_rows() on a non-object PHP致命错误:在非对象上调用成员函数num_rows() - PHP Fatal error: Call to a member function num_rows() on a non-object 在非对象上调用成员函数 num_rows() - Call to a member function num_rows() on a non-object 使用codeigniter调用非对象上的成员函数num_rows() - Call to member function num_rows() on non object using codeigniter 致命错误:在第137行的/home/*/public_html/application/core/MY_Controller.php中的非对象上调用成员函数num_rows() - Fatal error: Call to a member function num_rows() on a non-object in /home/*/public_html/application/core/MY_Controller.php on line 137 在模型文件中的非对象上调用成员函数num_rows() - Call to a member function num_rows() on a non-object in model file Codeigniter 致命错误:调用非对象上的成员函数 query() - Codeigniter Fatal error: Call to a member function query() on a non-object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM