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条)

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置