【发布时间】:2017-12-19 11:38:20
【问题描述】:
` 查询表格
<div class="row">
<label class="col-md-3" for="zones">Zones in Bangalore</label>
<div class="checkboxes">
<p id="zones"><input type="checkbox" name="zones[]" class="zones">CBD
<input type="checkbox" name="zones[]" class="zones">North
<input type="checkbox" name="zones[]" class="zones">South
<input type="checkbox" name="zones[]" class="zones">East
<input type="checkbox" name="zones[]" class="zones">West</p>
</div>
</div>
<div class="row">
<label class="col-md-3" for="propertytype">Property Type</label>
<div class="checkboxes">
<p id="propertytype">
<input type="checkbox" name="propertytype[]" class="propertytype">Apartment
<input type="checkbox" name="propertytype[]" class="propertytype">Raw House
<input type="checkbox" name="propertytype[]" class="propertytype">Villa
<input type="checkbox" name="propertytype[]" class="propertytype">Residential Plot</p>
</div>
</div>
$('.zones').on('change', function() {
$('.zones').not(this).prop('checked', false);
});
$('.propertytype').on('change', function() {
$('.propertytype').not(this).prop('checked', false);
});
这是脚本代码仅选中一个复选框的代码。我无法弄清楚如何存储此复选框值。尝试存储此数据时出现错误。我试图检查 if 条件但无法获取代码。我的项目中还有 4 个类似的复选框,我必须将所有数据存储在一个数据库表中。你能帮我解决这个问题吗?
在控制器中:
$numreg= '/^[7-9]{1}[0-9]{9}$/';
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
if(isset($_POST['submit'])){
$this->form_validation->set_rules('zones[]', 'zones of Bangalore', 'required');
$this->form_validation->set_rules('propertytype[]', 'Property type', 'required');
}
if ($this->form_validation->run() == TRUE)
{
$data_to_store = array(
'zones'=> $_POST['zones'],
'propertytype'=> $_POST['propertytype']
);
$this->db->insert('enquiry', $data_to_store);
}`
【问题讨论】:
-
出现什么错误?
-
遇到 PHP 错误严重性:通知消息:数组到字符串的转换文件名:mysqli/mysqli_driver.php 行号:553
-
你可以试试vinothini answer :)
-
一次我只选择一个复选框
标签: mysql codeigniter validation checkbox