[英]inserting selected option from dropdown into db codeigniter
我一直在编写一个注册表单,其中有一个从关联数组填充的下拉列表,如下所示:
**<?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中。 有什么问题?
您在选择列表中看到的内容与从中传递的值不同
$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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.