dpz
dpz

Reputation: 79

i can't insert multiselect jquery value into database

i use jquery multiselect to show my data

this is how i show my data on my view


<td><select class="multiselect" multiple="multiple" name="id_c[]">
        <?php foreach ($test as $data): ?>
        <option value="<?php echo $data->id_a ?>" ><?php echo $data->nama ?></option>
        <?php endforeach; ?>
        </select><td>

and this how i save into database in my model

function save(){    

        $id_c= $this->input->post('id_c');
        var_dump($id_c);
        $idb = '';
        $count = count($id_c);
        $i=0;
        foreach($id_c as $e){
            if($i < $count -1){
                $idb .= $e.', ';
            }else{
                $idb .= $e;
            }
            $i++;
        }

            $tanggal = $this->input->post('tanggal');
            $data=array(
                        'id_c'=>$idb,
                        'tanggal'=>$tanggal
                        );
            $this->db->insert('detail',$data);
    }

but when i click submit the value didn't go into database

i try to use var_dump and this what i get bool(false)


Message: Invalid argument supplied for foreach()

Upvotes: 1

Views: 939

Answers (1)

Arun Jain
Arun Jain

Reputation: 5464

Your save method should looks like:

function save(){    
    //echo "<pre>";
    //print_r($this->input->post()); //first try to check whether you are receiving posted data or not.
    //die;

    $id_c= $this->input->post('id_c');
    $idb = implode(',', $id_c);
    $tanggal = $this->input->post('tanggal');
        $data=array(
                    'id_c'=>$idb,
                    'tanggal'=>$tanggal
                    );
        $this->db->insert('detail', $data);
}

Upvotes: 1

Related Questions