Codeigniter invalid wrong email or password return message

I made a function in CodeIgniter so users can log into my page. When a user enters a wrong email or password I want to echo an error message like

For example Invalid email or password. But this is not working for me. I tried to do it with flashdata like this:

else {

$this->$session->$set_flashdata("Invalid email or password");

is should be

else {

$this->session->set_flashdata('error','Invalid email or password');
redirect(base_url()); # or redirect('login'); controller name

and in view

    echo $this->session->flashdata('error');