当我在 Codeigniter 中提交登录表单时,我一直收到“未定义”,我真的找不到问题,我尝试设置加密密钥,即使我没有使用它,但这并不能解决我们的问题
这是我的看法
<!--loads the header-->
<?php $this->load->view('abt-header');?>
<!--this is the login page-->
<div data-role="page" id="Abt-login" data-add-back-btn="true">
<div data-role="header" data-position="fixed">
<h1>Login</h1>
</div>
<div data-role="content">
<?php echo form_open('index.php/abovetheblues/login'); ?>
<div data-role="fieldcontain">
<p><?php echo validation_errors(); ?></p>
<p>
<label>Username: </label>
<?php echo form_input('username', set_value('username') ); ?>
</p>
<p>
<label>Password: </label>
<?php echo form_password('password', set_value('password') ); ?>
</p>
<p>
<?php echo form_submit('submit', 'Submit'); ?>
</p>
</div>
<?php echo form_close(); ?>
</div>
</div>
这是我在模型中的功能
// checks username and password against the database
function check_login() {
$this->load->database();
$this->db->where('email', $this->input->post('email'));
$this->db->where('password', $this->input->post('password'));
$q = $this->db->get('user');
if ($q->num_rows() == 1) {
return true;
}
}
这是我在控制器中的代码
public function login() {
$this->form_validation->set_rules('username', 'Username', 'trim|required|alpha_numeric|min_length[6]|max_length[12]|xss_clean');
$this->form_validation->set_rules('password', 'Password', 'trim|required|alpha_numeric|min_length[6]|max_length[6]|xss_clean');
if ($this->form_validation->run() == FALSE) {
// return main page if submitted form is invalid.
$this->load->view('abt_login');
} else {
$this->load->model('abt_db');
$q = $this->abt_db->check_login();
if($q)
{
$data = array(
'email' => $this->input->post('email'),
'password' => $this->input->post('password'),
);
$this->session->set_userdata($data);
redirect('index.php/abovetheblues/abt-abovetheblues');
}
else
{
redirect('index.php/abovetheblues/abt_selfhelp');
}
}
}