[eluser]Corbee[/eluser]
I have a login form that directs people to the dashboard, but whenever there is no user yet, I kept getting undefined index error.
like this
Code:
Severity: Notice
Message: Undefined index: userid
Filename: controllers/welcome.php
Line Number: 13
What am I missing?
Controller
Code:
class Admin extends Controller {
function Admin()
{
parent::Controller();
session_start();
}
function index()
{
if ($this->input->post('username'))
{
$u = $this->input->post('username');
$pw = $this->input->post('password');
$this->MAdmins->verifyUser($u,$pw);
if ($_SESSION['userid']>0)
{
redirect('dashboard','refresh');
}
else
{
redirect('admin/index','refresh');
}
}
$data['main'] = 'login';
$data['title'] = "Insurance Experts | Admin Login";
$this->load->view('template',$data);
}
}
Model
Code:
class MAdmins extends Model
{
function MAdmins()
{
parent::Model();
}
function verifyUser($u,$pw)
{
$_SESSION['userid'] = NULL;
$this->db->select('memberID,username');
$this->db->where('username',$u);
$this->db->where('Password',$pw);
$this->db->where('memberID','2');
$this->db->where('type','admin');
$this->db->limit(1);
$q = $this->db->get('member');
if ($q->num_rows() > 0)
{
$row = $q->row_array();
$_SESSION['userid'] = $row['memberID'];
$_SESSION['username'] = $row['username'];
}
else
{
$this->session->set_flashdata('error','Sorry, your username or password is incorrect!');
}
}
}