[eluser]chazy (aldever calvo)[/eluser]
hello.. i need help regarding form_multiselect...
whenever i tried to insert the multiple selected value into the db, it always gives me error:
Code:
A Database Error Occurred
Error Number:
ERROR: invalid input syntax for integer: "13[]" LINE 1: ..."ch_act_mat_mat_id", "ch_act_mat_act_id") VALUES ('13[]', '6... ^
INSERT INTO "choy_activity_materials" ("ch_act_mat_mat_id", "ch_act_mat_act_id") VALUES ('13[]', '6')
heres my model:
Code:
function AddSetMaterial($actNum, $actMat)
{
$data = array(
'ch_act_mat_mat_id' => $actMat.'[]',
'ch_act_mat_act_id' => $actNum
);
return $this->db->insert('choy_activity_materials', $data);
}
function get_mat_dropdown()
{
$this->db->from('choy_material');
$this->db->order_by('choy_mat_name');
$result = $this->db->get();
$return = array();
if($result->num_rows() > 0)
{
$return[''] = 'Please select (Hold [ctrl] for multiple selection)';
foreach($result->result_array() as $row)
{
$return[$row['ch_mat_id']] = $row['choy_mat_name'];
}
}
return $return;
}
view
Code:
<table>
<tr>
<th colspan="2">
SET ACTIVITY MATERIALS</th>
</tr>
<tr><?php $actNum = $this->input->post('actNum');?>
<td><label>*Activity Number : <span class="small">Select from existing activity</span></label></td>
<td><?php echo form_dropdown('actNum', $activity, 'style="height:25px;"')?></td>
</tr>
<tr>
<td></td>
<td><?php echo form_error('actNum')?>;</td>
</tr>
<tr><?php $actMat = $this->input->post('actMat[]');?>
<td><label>*Material :<span class="small">Choose from the list of existing materials (Sort Alphabetically)</span></label></td>
<td><?php echo form_multiselect ('actMat[]', $material, $actMat, 'style=height:200px;"')?></td>
</tr>
<tr>
<td></td>
<td><?php echo form_error('actMat')?></td>
</tr>
<tr>
<td> </td>
<td><?php echo form_submit('', 'Set Activity Mterials');?></td>
</tr>
</table>
controller
Code:
function setmaterials()
{
$activity = $this->activities_model->get_actnum_dropdown();
$data['activity'] = $activity;
$material = $this->activities_model->get_mat_dropdown();
$data['material'] = $material;
//Validate Form
$this->form_validation->set_rules('actNum', 'Activity Number', 'trim|required');
$this->form_validation->set_rules('actMat', 'Material', 'trim|required');
if($this->form_validation->run() == FALSE)
{
$this->load->view('activities/activities_setmaterials_form', $data);
}
else
{
//The form is validated
$actNum = $this->input->post('actNum');
$actMat = $this->input->post('actMat');
$this->activities_model->AddSetMaterial($actNum, $actMat);
}}
PLease help me... school deadline is almost up... T.T