both variables are undefined($usuario and $senha) :(
this code is suposed to do login, but the model isn't receiving the variables
Controller
public function login(){
$this->load->model('Usuario_model');
$this->Usuario_model->usuario = $this->input->post('usuario');
$this->Usuario_model->senha = sha1($this->input->post('senha'));
$dados = $this->Usuario_model->login();
foreach($dados AS $row){
$level = $row->level;
$usuario = $row->login;
}
if(($dados)){
$newdata = array(
'usuario' => "$usuario",
'level' => $level,
'logged_in' => TRUE
);
$this->session->set_userdata($newdata);
$session = $this->session->all_userdata();
redirect("index.php/voe/index");
}
}
Model
public function login(){
$query = $this->db->query("SELECT * FROM usuario WHERE login = '$usuario' AND senha = '$senha'");
$query = $query->result();
return $query;
}
There's an indication from these two lines:
$this->Usuario_model->usuario = $this->input->post('usuario');
$this->Usuario_model->senha = sha1($this->input->post('senha'));
that there are variables inside of the Usuario-model
that you have accessed and stored, but the login()
function is trying to access variables inside of the scope of the function, not the scope of the model. Using $this->
will allow you to access the private, public, or protected variables of the class that the function lives in. Make sure you try:
public function login(){
$query = $this->db->query("SELECT * FROM usuario WHERE login = '".$this->usuario."' AND senha = '".$this->senha."'");
$query = $query->result();
return $query;
}
To use a PDO-like approach, as per the CI docs , you should instead do:
public function login() {
$query = $this->db->query(
'SELECT * FROM usuario WHERE login = ? AND senha = ?',
array($this->usuario, $this->senha)
)
$query = $query->result();
return $query;
}
This will give you safer queries with escaped user values.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.