我是codeigniter的新手,所以这感觉就像一个愚蠢的问题,但我一直在寻找。我使用codeigniter创建了一个登录和帐户注册页面。提交表格后,我明白了:
Error Number: 1146
Table 'users.user' doesn't exist
INSERT INTO `user` (`email`, `firstname`, `lastname`, `username`, `password`, `hint`) VALUES ('blah', 'blah', 'blah', 'blah', 'fa348efcd3bb1a1fc6ba5c2c912cf402', 'Brown')
Filename: F:\htdocs\system\database\DB_driver.php
Line Number: 330
问题是该表被称为"用户"不是用户。我的问题是如何找到表名,以便我可以将其更改为" users"而不是"用户"。
这是控制器:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class User extends CI_Controller{
public function __construct()
{
parent::__construct();
$this->load->model('user_model');
}
public function index()
{
if(($this->session->userdata('username')!=""))
{
$this->welcome();
}
else{
$data['title']= 'Home';
$this->load->view('header_view',$data);
$this->load->view("registration_view.php", $data);
$this->load->view('footer_view',$data);
}
}
public function welcome()
{
$data['title']= 'Welcome';
$this->load->view('header_view',$data);
$this->load->view('welcome_view.php', $data);
$this->load->view('footer_view',$data);
}
public function login()
{
$email=$this->input->post('email');
$password=md5($this->input->post('pass'));
$result=$this->user_model->login($email,$password);
if($result) $this->welcome();
else $this->index();
}
public function thank()
{
$data['title']= 'Thank';
$this->load->view('header_view',$data);
$this->load->view('thank_view.php', $data);
$this->load->view('footer_view',$data);
}
public function registration()
{
$this->load->library('form_validation');
// field name, error message, validation rules
$this->form_validation->set_rules('username', 'User Name', 'trim|required|min_length[4]|xss_clean');
$this->form_validation->set_rules('email', 'Your Email', 'trim|required|valid_email');
$this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[32]');
$this->form_validation->set_rules('firstname', 'First Name', 'trim|required|min_length[3]|max_length[32]');
$this->form_validation->set_rules('lastname', 'Last Name', 'trim|required|min_length[2]|max_length[32]');
$this->form_validation->set_rules('hint', 'hint', 'trim|required|min_length[2]|max_length[32]');
if($this->form_validation->run() == FALSE)
{
$this->index();
}
else
{
$this->user_model->add_user();
$this->thank();
}
}
public function logout()
{
$newdata = array(
'user_id' =>'',
'username' =>'',
'user_email' => '',
'logged_in' => FALSE,
);
$this->session->unset_userdata($newdata );
$this->session->sess_destroy();
$this->index();
}
}
?>
型号:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class User_model extends CI_Model {
public function __construct()
{
parent::__construct();
}
function login($email,$password)
{
$this->db->where("email",$email);
$this->db->where("password",$password);
$query=$this->db->get("users");
if($query->num_rows()>0)
{
foreach($query->result() as $rows)
{
//add all data to session
$newdata = array(
'user_id' => $rows->id,
'user_name' => $rows->username,
'user_email' => $rows->email,
'logged_in' => TRUE,
);
}
$this->session->set_userdata($newdata);
return true;
}
return false;
}
public function add_user()
{
$data=array(
'email'=>$this->input->post('email'),
'firstname'=>$this->input->post('firstname'),
'lastname'=>$this->input->post('lastname'),
'username'=>$this->input->post('username'),
'password'=>md5($this->input->post('password')),
'hint'=>$this->input->post('hint')
);
$this->db->insert('user',$data);
}
}
?>
答案 0 :(得分:2)
您的插入方法正在尝试插入表user
。将user
更改为users
public function add_user()
{
$data=array(
'email'=>$this->input->post('email'),
'firstname'=>$this->input->post('firstname'),
'lastname'=>$this->input->post('lastname'),
'username'=>$this->input->post('username'),
'password'=>md5($this->input->post('password')),
'hint'=>$this->input->post('hint')
);
$this->db->insert('user',$data);
}
答案 1 :(得分:0)