我一直在处理一个注册表单,其中有一个从关联数组填充的下拉列表,如下所示:
**<?php
**$options = array(
'cbaringo' => 'Baringo',
'cbomet' => 'Bomet',
'cbungoma' => 'Bungoma',
'cbusia' => 'Busia',
'celgeyo' => 'Elgeyo Marakwet',
'cmigori' => 'Migori',**
?>**
我想将用户选择的选项插入数据库,如下所示
**$data = array(
'scounty' => $this->input->post('counties'),
'ssubcounty' => $this->input->post('subcounty'),
'sname' => $this->input->post('dschoolname'),
'skcpecode' => $this->input->post('dkcpecode'),
'stelno' => $this->input->post('dtelno'),
'steampatronname' => $this->input->post('dpatroname'),
'steampatronemail' => $this->input->post('dpatronemail'),
'steampatrontelno' => $this->input->post('dpatrontelno'),
's_password' => $this->input->post('scpassword')
);**
这样下拉这个下拉:
**echo form_dropdown('counties', $options, 'cdefault');**
以上行按预期显示下拉列表中的选项
//inserted data into db
**$this->my_model->insert_data($data);**
然而,插入键而不是关联数组中的值被插入到db中。有什么问题?
答案 0 :(得分:0)
您在选择列表中看到的内容与从中传递的值不同
$options =
// the value // what the user sees in the drop down
array(
'cbaringo' => 'Baringo',
'cbomet' => 'Bomet',
'cbungoma' => 'Bungoma',
'cbusia' => 'Busia',
'celgeyo' => 'Elgeyo Marakwet',
'cmigori' => 'Migori',**
?>
所以如果他们选择Baringo,那么传递的值应该是cbaringo