Welcome Guest, Not a member yet? Register   Sign In
cannot insert data into database
#1

[eluser]ubl_coder[/eluser]
i use CI 1.7.1 and ODBC database driver, this is my database config:

Code:
$db['default']['hostname'] = "sipdb";
$db['default']['username'] = "";
$db['default']['password'] = "";
$db['default']['database'] = "sipdb";
$db['default']['dbdriver'] = "odbc";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";

sipdb is ODBC DSN name.

This is a function in my model to insert data from input form :

Code:
function simpan() {
    $data = array(
        'kode_barang'=>$this->input->post('kd_brg'),
        'nama'=>$this->input->post('nm_brg'),
        'satuan'=>$this->input->post('satuan'),
        'harga'=>$this->input->post('harga'),
        'stok'=>$this->input->post('stok')
    );
        
    $this->db->insert('barang', $data);
    }

The problem is when I submitted input form then i got an error like this :

<b>Fatal error: </b>Call to undefined method Barang::_remove_invisible_characters() in <&lt;base_path&gt;&gt;\system\database\drivers\odbc\odbc_driver.php on line 248.

"Barang" is the name of my app controller class.

I don't know why and i couldn't find out how to make it worked. Any solutions?
#2

[eluser]Mackstar[/eluser]
Try an older or new version of CI, it may be a bug in CI?? You could also go to see where the problem is, does the function it is trying to access exist??

Cheers

Richard
#3

[eluser]ubl_coder[/eluser]
system/database/drivers/odbc/odbc_driver.php line 248 :

Code:
// ODBC doesn't require escaping
return $CI->_remove_invisible_characters($str);

i try to search and can't find any in this file. Maybe it exist in another file?
#4

[eluser]Mackstar[/eluser]
The function lives in Input.php in the main CI system libraries, so the function does exist, I don't know why it is having trouble finding it. Maybe it is not loading properly??

Bug? Incomplete file, maybe you could check this file and check the function exists??

Cheers

Richard
#5

[eluser]mdcode[/eluser]
Two things strike me as being evident:

1) are you sure that the database you are attempting to connect to does not require a username or password? If they do, insert these in the appropriate fields in the config.

2) You insert query is incorrect. The first parameter should be the table in which you want to insert the data, not the name of the class. Try changing barang to a table in you database such as:
Code:
$this->db->insert('blog',$data);
#6

[eluser]ubl_coder[/eluser]
my database doesn't require username/password. I use ms access. There is no problem with database connection.

i tried to change the name of controller to something else like 'product' and still got a same error.

'barang' is a table name. i think that's correct.

:-S
#7

[eluser]TheFuzzy0ne[/eluser]
Please could we see the entire model declaration? It's almost as if you aren't extending the Model class.
#8

[eluser]ubl_coder[/eluser]
Here is my model : ( mbarang.php )

Code:
&lt;?php

if ( ! defined('BASEPATH')) exit('No direct script access allowed');

Class Mbarang extends Model {
    
    function __construct() {
        parent::Model();    
    }
    
    function simpan() {
         $data = array(
             'kode_barang'=>$this->input->post('kd_brg'),
            'nama'=>$this->input->post('nm_brg'),
            'satuan'=>$this->input->post('satuan'),
            'harga'=>$this->input->post('harga'),
            'stok'=>$this->input->post('stok')
        );
    
        $this->db->insert('barang', $data);
    }
}
?&gt;

Any statements are incorrect?
#9

[eluser]TheFuzzy0ne[/eluser]
Not that I can see. Although I'd recommend you omit the closing PHP tag, but that's to do with style, not your problem.

What version of CodeIgniter are you running? I can see a potential problem.
#10

[eluser]ubl_coder[/eluser]
1.7.1. Using ms access database




Theme © iAndrew 2016 - Forum software by © MyBB