0
votes

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

2
are you doing other successful inserts elsewhere in the app? - charlietfl
@charlietfl I'm just starting codeigniter - Rochelle
fine...just curious if you have any other database inserts working or selects even for that matter. Something is mis-configured somewhere...not sure where though - charlietfl
Show us your /application/config/database.php content - Rizwan M.Tuman
table name seems different in the error message and insert query - Shihas

2 Answers

0
votes

In your database.php you have 'dbprefix' => '1', and you need to change it to 'dbprefix' => '',

0
votes

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 !