I am encountering an error when I submit my form:
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.
For context, here is my save_patient_info()
method:
function save_patient_info()
{
$data['name'] = $this->input->post('name');
$data['email'] = $this->input->post('email');
$data['password'] = sha1($this->input->post('password'));
$data['address'] = $this->input->post('address');
$data['phone'] = $this->input->post('phone');
$data['sex'] = $this->input->post('sex');
$data['birth_date'] = strtotime($this->input->post('birth_date'));
$data['age'] = $this->input->post('age');
$data['blood_group'] = $this->input->post('blood_group');
$this->db->insert('patient',$data);
$patient_id = $this->db->insert_id();
move_uploaded_file(
$_FILES["image"]["tmp_name"],
"uploads/patient_image/" . $patient_id . '.jpg'
);
}
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']