Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Hi i hava data in array like this :

$data = Array
       (
[0] => Array
    (
        [kode_pbt] => PBT3-2012-10-19
        [kodebr] => 8992802618731
        [harga] => 25905.00
        [jml] => 1
        [subtotal_harga] => 25905
    )

[1] => Array
    (
        [kode_pbt] => PBT3-2012-10-19
        [kodebr] => 8992388112401
        [harga] => 1340.00
        [jml] => 1
        [subtotal_harga] => 1340
    )

  )

my problem is when i want to insert to database white this code : $this->db->insert($table, $data) i got an error: Message: Array to string conversion I have changed to $this->db->insert_batch($table, $data), but i got error '500 internal server error'. Thank for your assist.

This is my full function code in controller :

function save_pbt($kode = -1) {
    $pbt_detail = array();
    $pbt_data = array(
        'kode_pbt' => trim($this->input->post('kode_pbt')),
        'unit_pemakai' => trim($this->input->post('unit_pemakai')),
        'jml_item' => trim($this->input->post('jml_item')),
        'total_harga' => trim($this->input->post('total_harga')),
        'tgl_pbt' => date('Y-m-d'),
        'status' => 0
    );
    for ($i = 0; $i <= $this->input->post('max_i'); $i++) {
        if ($this->input->post('kodebr' . $i)) {
            $detail_pbt = array(
                'kode_pbt' => $this->input->post('kode_pbt'),
                'kodebr' => $this->input->post('kodebr' . $i),
                'harga' => $this->input->post('beli' . $i),
                'jml' => $this->input->post('jml' . $i),
                'subtotal_harga' => $this->input->post('subtotal' . $i)
            );
            array_push($pbt_detail, $detail_pbt);
        }
    }


    $this->db->trans_begin();
    $this->Pbt_model->insert_pbt($pbt_data);
    $this->Pbt_model->insert_detail_pbt($pbt_detail);
    if ($this->db->trans_status() == FALSE) {
        $this->db->trans_rollback();

        echo "TRANSACTION ROLLBACK";
    } else {
        $pbt_data['detail'] = $pbt_detail;
        $url = SERVER_SIKOPIT . 'service/service?process=pbt&api_key=' . API_KEY;
        $response = json_encode($this->rest_helper($url, $pbt_data, "POST"));
        echo $response;
        $response = json_decode($response);
        if ($response->status == true) {
            $this->db->trans_commit();
            echo "TRANSACTION SUCCESS";
            redirect(site_url('receivings'));
        } else {
            $this->db->trans_rollback();
            echo "INSERT PBT BARU GAGAL !!";
            echo "TRANSACTION ROLLBACK";
        }
    }
}
share|improve this question
$this->db->insert_batch($table, $data) is correct so problem is somewhere else.. paste your code where you using this – GBD Oct 21 '12 at 10:07
insert_batch() should be what you need, but we can't debug with a generic 500 error message - could be anything! in your development environment you will need to ini_set('display_errors',1); and error_reporting(E_ALL|E_STRICT); – benedict_w Oct 21 '12 at 10:07

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.