我正在尝试创建一个登录系统而我收到此数据库错误
您的SQL语法有错误;检查与MariaDB服务器版本对应的手册,以便在“SET
last_activity
= 1467333267,user_data
='a:3:{s:9:\”user_data \“; s附近使用正确的语法:0:\“\”'在第1行UPDATE SET
last_activity
= 1467333267,user_data
='a:3:{s:9:\“user_data \”; s:0:\“\”; s:5:\“ email \“; s:16:\”ocyl28@yahoo.com \“; s:12:\”is_logged_in \“; i:1;}'WHEREsession_id
='570d7ba3d7f11a9a35264ed276368480'文件名:C:/xampp/htdocs/CodeIgniter/system/database/DB_driver.php
行号:691
这是我的控制器代码:
class Template extends CI_Controller {
public function index()
{
$this->login();
}
public function login()
{
$this->load->view('Login Template.php');
}
public function admin()
{
if ($this->session->userdata('is_logged_in')) {
$this->load->view('Template 3.php');
}
else {
echo 'cannot login';
}
}
public function login_validation()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('email' , 'Email', 'required|trim|callback_validate_credentials');
$this->form_validation->set_rules('password' , 'Password', 'required|md5|trim');
if ($this->form_validation->run()) {
$data = array (
'email' => $this->input->post('email'),
'is_logged_in' => 1
);
$this->session->set_userdata($data);
redirect('template/admin');
}
else
{
echo 'fail';
}
}
public function validate_credentials()
{
$this->load->model('users');
if ($this->users->can_log_in()) {
return true;
}
else
{
$this->form_validation->set_message('validate_credentials', 'fail to login');
return false;
}
}
public function about()
{
$this->load->view('About this site.php');
}
public function logout()
{
$this->session->sess_destroy();
redirect('template/login');
}
这是我的型号代码:
class Users extends CI_Model
{
public function can_log_in()
{
$this->db->where('email', $this->input->post('email'));
$this->db->where('password', md5($this->input->post('password')));
$query = $this->db->get('registered_users');
if ($query->num_rows() == 1) {
return true;
}
else
{
return false;
}
}
答案 0 :(得分:0)
SQL语句中缺少表名。