Codeigniter $ this-> db-> get_where

时间:2016-07-20 11:18:16

标签: php codeigniter

无法提交表单,我有错误。 遇到PHP错误

  

严重性:注意

     

消息:尝试获取非对象的属性

     

文件名:controllers / Admin.php行号:253 Backtrace:文件:   C:\ OpenServer的\域\ medicalsystem.com \应用\控制器\ admin.php的   行:253功能:_error_handler   块引用

if ($task == "create"){

    $email = $_POST['email'];       
    $patient = $this->db->get_where('patient', array('email' => $email))->row()->name;      
    if ($patient == null) {
        $this->crud_model->save_patient_info();
        $this->session->set_flashdata('message', get_phrase('patient_info_saved_successfuly'));
    } else {
        $this->session->set_flashdata('message', get_phrase('duplicate_email'));
    }
    redirect(base_url() . 'index.php?admin/patient');
}

错误代码

$patient = $this->db->get_where('patient', array('email' => $email))->row()->name;

此行存在问题。

1 个答案:

答案 0 :(得分:1)

试试这个:

if ($task == "create"){

    $email = $_POST['email'];
    $patient = $this->db->get_where('patient', array('email' => $email))->result_array();

    if ($patient == null) {
        $this->crud_model->save_patient_info();
        $this->session->set_flashdata('message', get_phrase('patient_info_saved_successfuly'));
    } else {
        $this->session->set_flashdata('message', get_phrase('duplicate_email'));
    }

    redirect(base_url() . 'index.php?admin/patient');
}

如果您想访问患者姓名,则可以$patient['name']

进行访问