Vasyl Vandych
Vasyl Vandych

Reputation: 123

Codeigniter $this->db->get_where

not work submit the form, I have an error. A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: controllers/Admin.php Line Number: 253 Backtrace: File: C:\OpenServer\domains\medicalsystem.com\application\controllers\Admin.php Line: 253 Function: _error_handler Blockquote

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');
}

Error line code

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

this line has a problem.

Upvotes: 1

Views: 13294

Answers (1)

Harshad Hirapara
Harshad Hirapara

Reputation: 462

Try this:

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');
}

If you want to access patient name then you can access as $patient['name']

Upvotes: 3

Related Questions