I'm trying to create an array with the data I retrieve from the database, my code is like this
$usuario = $this->input->post("usuario");
$senha = $this->input->post("senha");
$this->db->select('id','usuario','senha','tipo');
$this->db->from('usuario');
$this->db->where('usuario',$usuario);
$this->db->where('senha',MD5($senha));
$login = $this->db->get()->result();
Here I query the database and retrieve the information in an array and save it in $ login. So I check if this array is not empty to authenticate the session
if ( is_array($login) && count($login) == 1) {
$this->session->set_userdata("logado", 1);
$this->load->view("admin/redireciona");
} else {
//caso a senha/usuário estejam incorretos, então mando o usuário novamente para a tela de login com uma mensagem de erro.
$dados['erro'] = "Usuário/Senha incorretos";
$this->load->view("login", $dados);
}
When doing this, I check if the user and password are correct in the bank and I authorize the login, in case of wrong, I inform the error. Now I wanted to pass some data to be able to use it in the future, and that's where I'm having problems.
$dadossessao = array(
'id' => $this->input->post('id'),
'nome' => $this->input->post('usuario'),
'tipo' => $this->input->post('tipo'),
'logado' => 1
);
The 'id' and 'type' are not returning values, which I do for these variables to receive the data that was retrieved from bd.
PS: My DB looks like this:
CREATE TABLE 'usuario' (
'id' int(11) NOT NULL,
'usuario' varchar(100) NOT NULL,
'senha' varchar(100) NOT NULL,
'tipo' int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO 'usuario' ('id', 'usuario', 'senha', 'tipo') VALUES
(1, 'teste', MD5('teste'), 1);