0

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Array' at line 1

INSERT INTO agenda () VALUES ('15','1','$2y$10$zE94wOg6xEpMfgU8bMzMmeBdKyFbU9UkmbwcTnlxftyD8jISDBpvG','1','admin'), Array

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

Line Number: 691

The Model

//insert data batch

public function save_batch($data){
        return $this->db->insert_batch('agenda', $data);
  }

The Controller

$no_agenda = $_POST['no_agenda'];
        $no_batch = $_POST['no_batch'];
        $nama_pelamar = $_POST['nama_pelamar'];
        $alamat = $_POST['alamat'];
        $no_hp = $_POST['no_hp'];
        $data = array();
        
        $data['users'] = $this->db->get_where('users', ['username' =>
        $this->session->userdata('username')])->row_array();

        $index = 0;
        foreach($no_agenda as $no_agenda){
            array_push($data, array(
                'no_agenda'=>$no_agenda,
                'no_batch'=>$no_batch[$index],
                'nama_pelamar'=>$nama_pelamar[$index],
                'alamat'=>$alamat[$index],
                'no_hp'=>$no_hp[$index],
                $data['users']
            ));

            $index++;
        }
        $sql = $this->Agenda_model->save_batch($data);//save data
  • I shouldn't see `$_POST` in a Codeigniter application's controller, there are dedicated methods for retrieving submitted data. I should not see `$this->db` in a Codeigniter application's controller, the active record calls all belong in the model. – mickmackusa Dec 12 '20 at 05:05
  • I would never write a `foreach()` where the incoming and the outgoing variable name is the same. (`$no_agenda as $no_agenda`) ...that's just asking for trouble. – mickmackusa Dec 12 '20 at 05:10
  • You cannot pack iterable data (`row_array()`) into an INSERTed row. – mickmackusa Dec 12 '20 at 05:14
  • I'd probably start by naming my array-type form fields using plural names. Then instead of using a separate counter, declare `$index` inside the loop: `foreach ($this->input->post("agenda_nos") as $index => $agenda_no") { ... // use $index where needed }` – mickmackusa Dec 12 '20 at 05:19

0 Answers0