Welcome Guest, Not a member yet? Register   Sign In
Undefined variable in model
#1

[eluser]Achmed1[/eluser]
Im getting this error message evertime when i want to query or want to search in the database from the model.


Undefined name and pass; line 17

LoginControler

Code:
<?php

class LoginController extends CI_Controller{


public function index(){
  $this->load->view('login');
  
}

public function check_login(){
  
  $this->form_validation->set_rules('username', 'Username', 'required');
  $this->form_validation->set_rules('password', 'Password', 'required|callback_verifyUser');  
  if($this->form_validation->run() == FALSE){
   $this->load->view('login');
  }else{
   redirect('HomeController/index');
  }
  
}

  public function verifyUser()
{
  $name = $this->input->post('username');
  $pass = $this->input->post('password');
  $this->load->model('LoginModel');
  if($this->LoginModel->login($name, $pass)){
   return true;
  }else{
   $this->form_validation->set_message('verifyUser' , 'incorret email');
  }

  

  
}





}

?>

LoginModel

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class LoginModel extends CI_Model {


function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }

public function login(){
  
  $this->db->select('name', 'pass');
  $this->db->from('members');
  $this->db->where('name', $name);
  $this->db->where('pass', $pass);
  
  $query = $this->db->get();
  
  if($query->num_rows()== 1){
   return true;
  }else{
   return false;
  }
}


}
#2

[eluser]Ed Robindon[/eluser]
I believe you need to quote $name and $pass in your where calls.

Ed
#3

[eluser]CroNiX[/eluser]
Select takes a single string, you're passing multiple strings...
Code:
$this->db->select('name', 'pass');
should be
Code:
$this->db->select('name, pass');
#4

[eluser]Achmed1[/eluser]
[quote author="CroNiX" date="1380741825"]Select takes a single string, you're passing multiple strings...
Code:
$this->db->select('name', 'pass');
should be
Code:
$this->db->select('name, pass');
[/quote]

The solution was this

This

Code:
public function login()

To This

Code:
public function login($name,$pass)

Thanks for the help




Theme © iAndrew 2016 - Forum software by © MyBB