简体   繁体   中英

codeigniter database error add

A Database Error Occurred

Error Number: 1146

Table 'gtv.1tbpost' doesn't exist

INSERT INTO 1tbpost ( post_title ) VALUES ('')

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

Line Number: 691


database.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' .

在你的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 !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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