Reputation: 129
In the below codeigniter code i have placed controller ,model and view .In my login i have create username ,password and college in dropdown for validate the user.But i got error in college_name drop down Message: Undefined variable: validate,Message: Invalid argument supplied for foreach().Pls help me to solve the issue. Controller
function college()
{
$this->load->helper('url');
$data = array();
$this->load->model("membership_model");
$data['validate'] = $this->Membership_model->validate();
$this->load->view('login_form');
}
function validate_credentials()
{
$this->load->model('membership_model');
$query = $this->membership_model->validate();
if($query) // if the user's credentials validated...
{
$data = array(
'username' => $this->input->post('username'),
'is_logged_in' => true
);
if($query->num_rows()>0){
$status = $query->row()->account_status;}
else {
$status = ''; }
//Account active
if($status == 'active')
{
$this->session->set_userdata($data);
redirect('site1/members_area');
}
else if ($status == 'inactive')//Account In active
{ $this->inactive();
}
else // incorrect username or password
{
$this->invalid();
}
}
}
model:
function validate()
{
$this->db->where('username', $this->input->post('username'));
$this->db->where('password', md5($this->input->post('password')));
$this->db->where('college_name', $this->input->post('college_name'));
$query = $this->db->query("SELECT college_name FROM membership ");
$query = $this->db->get('membership');
return $query->result();
}
view:
<?php
echo form_open('login/validate_credentials');
echo form_input('username', 'Username');
echo form_password('password', 'Password');
$array = array();
foreach($validate as $row ){
$array[] = $row->college_name;
}
echo form_dropdown('validate', $array);
echo form_submit('submit', 'Login');
echo anchor('login/signup', 'Create Account');
echo form_close();
?>
Upvotes: 0
Views: 321
Reputation: 107
Try to use correct camel case here
$this->Membership_model->validate();
as $this->membership_model->validate();
Also you need to pass the $data variable to view file.
$this->load->view('login_form',$data);
EDIT:
In the validate() method you used the same variable ($query) for 2 different queries and return the query result. Make sure you had returned the correct result there.
Upvotes: 1