简体   繁体   English

codeigniter 数据库错误添加

[英]codeigniter database error add

A Database Error Occurred发生数据库错误

Error Number: 1146错误编号:1146

Table 'gtv.1tbpost' doesn't exist表 'gtv.1tbpost' 不存在

INSERT INTO 1tbpost ( post_title ) VALUES ('')插入1tbpost ( post_title ) 值 ('')

Filename: C:/xampp/htdocs/1/system/database/DB_driver.php文件名:C:/xampp/htdocs/1/system/database/DB_driver.php

Line Number: 691行号:691


database.php /数据库.php /

$active_group = 'default';
$query_builder = TRUE;

$db['default'] = array(
    'dsn'   => '',
    'hostname' => 'localhost',
    'username' => 'root',
    'password' => '',
    'database' => 'gtv',
    'dbdriver' => 'mysqli',
    'dbprefix' => '1',
    'pconnect' => FALSE,
    'db_debug' => (ENVIRONMENT !== 'production'),
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);

model:型号:

public function add(){
            $data=array(

            'post_title'=>$this->input->post('title'),

            );
        $this->db->insert('tbpost',$data);
        }

controller:控制器:

   public function add_validate(){
        $this->load->library('form_validation');

        $this->form_validation->set_rules('title', 'Title', 'trim|required|min_length[6]|regex_match[/^[A-Za-z0-9 .]+$/]');
        $this->form_validation->set_rules('image', 'Image', 'trim');
        $this->form_validation->set_rules('text', 'Text', 'trim|required|min_length[2]');

        $this->form_validation->set_message('required', '%s is required.');
        $this->form_validation->set_message('min_length', 'minimum characters for %s is %s');
        $this->form_validation->set_message('regex_match', '%s is not in the correct format');

        if($this->form_validation->run() == FALSE){
            if($this->input->post('add') == "post"){
                $this->gtvmod->add();
            }else if($this->input->post('add') == "save"){
                $this->index();
            }else if($this->input->post('add') == "cancel"){
                $this->index();
            }else{
                $this->index();
            }

        }else{
            if($this->input->post('add') == "post"){
                $this->add();//punta model
            }else if($this->input->post('add') == "save"){
                $this->index();//punta model
            }else if($this->input->post('add') == "cancel"){
                $this->index();//punta model
            }else{
                $this->index();//punta model
            }
        }
    }

problem I specify that my table is 'tbpost' but the error says that I insert into table '1tbpost' .问题我指定我的表是 'tbpost' 但错误说我插入了表 '1tbpost' 。

在你的database.php 你有'dbprefix' => '1',你需要把它'dbprefix' => '',

you have called a not existing table in your database so check the table names that you have called.您在数据库中调用了一个不存在的表,因此请检查您调用的表名。

if you have form validation library check the rules the table's name is maybe hidden there haha如果你有表单验证库检查规则表的名称可能隐藏在那里哈哈

relax and enjoy programming !放松并享受编程!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM