duanshang9426
2014-12-03 01:17
浏览 40
已采纳

在codeigniter哪里找到表?

I am new with codeigniter so this feels like a silly question but I have been looking all over. I have created a log in and account registration page using codeigniter. After submitting a form, I get this:

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

The problem is that the table is called "users" not user. My question is how do I find the table name so I can change it to "users" instead of "User".

Here is the controller:

    <?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();
     }
    }
    ?>

Model:

<?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);
 }
}
?>
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doupeizheng3918 2014-12-03 01:22
    已采纳

    Your insert method is trying to insert into the table user. Change user to 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条)

相关推荐 更多相似问题