我目前正在建立一個網絡學生註冊,我使用的是CodeIgniter。我已經設法將表單插入到我的數據庫中,並且我使用提交表單中的電子郵件和密碼進行登錄。我的登錄頁面出現問題,無法檢查數據庫中是否存在電子郵件或密碼,也無法重定向到所需的頁面。CodeIgniter登錄和會話
這是我的控制器
public function index()
{
$data = '';
if($this->input->post('submit'))
{
$this->form_validation->set_rules('email','email','required');
$this->form_validation->set_rules('password','password','md5|required');
if($this->form_validation->run())
{
$email = $this->input->post('email');
$password = md5($this->input->post('password'));
$this->load->model('testmodel','user');
$member = $this->user->selectUser("WHERE email = '$email' AND password = '$password'");
if($member->has_rows())
{
$user_data = array(
'name' => $member->row('name'),
'nisn' => $member->row('nisn'),
'email' => $member->row('email'),
'logged_in_admin' => TRUE
);
$this->session->set_userdata($user_data); redirect('pages/userpage/userpage');
}else
{
$data['message'] = '<div class = "error">Username and password wrong!</div>';
}
}else
{
$data['message'] = '<div class = "error">' . validation_errors() . '</div>';
}
}
$this->load->view('pages/userlogin/userlogin',$data);
}
這是testmodel的selectuser功能
public function selectUser($where = '', $sort = 'DESC', $limit = '')
{
$query = "
SELECT SQL_CALC_FOUND_ROWS * FROM student_table
$where
ORDER BY ticketnumber $sort
$limit
";
return $this->db->query($query);
}'
您收到的錯誤是什麼? –
您是否有從您的代碼獨立測試的工作數據庫連接? – DrCord
theres沒有錯誤,它只是無法重定向到我想要的網頁,是的,它是 –