0
I am trying to create an array with the data I recover 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 make the query in the bank and retrieve the information in an array and save in $login. Dai 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 procedure, I check if the user and password are correct in the bank and authorize the login, if wrong, I report the error. Now I wanted to pass some data to be able to use in the future within the application, 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, what I do so that these variables receive the data that was recovered from the bd.
PS: My DB is 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);
Okay, I’ve noticed that the problem ta being the syntax of $this->input->post('...'), but I’m not finding the correct syntax.
– Anderson Moreira
Change
$this->input->post('id')
for$login[0]['id']
and$this->input->post('tipo')
for$login[0]['tipo']
you are not passing these values via form but recovering from your query in the database, so just take the variable that brings this data and for them in its function that creates the session.– William Novak
@William Novak this way gave the error 'Function name must be a string'. The variable did not receive the database data. As I commented, I know the problem is being this statement, but as I’m not very good with php, I’m having this difficulty.
– Anderson Moreira
Gives a
print_r($login)
and see if the variable is really taking the database data by your query.– William Novak
@William Novak I just did the test here, and the $login variable is not getting any data really, so I’m not getting the user data back.
– Anderson Moreira