1
我有一个表单,具有各种输入字段和3个复选框。如何将这些复选框值存储在de数据库中的数据库的相同字段中?将复选框值传递给包含其他表单值的数据库?
这是我的代码
形式:
<div class="pro-input pro-field">
<label for="name" class="label_title">Name</label>
<?php echo form_input($title); ?>
</div><!--pro-input-->
<div class="pro-text pro-field">
<label for="name" class="label_text">Text</label>
<?php echo form_textarea($text); ?>
</div>
<div class="pro-input pro-field">
<label for="name" class="label_title">URL</label>
<?php echo form_input($url);?>
</div><!--pro-input-->
<div class="pro-checkbox pro-field">
<label for="name" class="label_title">Categorie</label>
<div class="pro-check">
<?php
echo form_label('Code', 'code');
echo form_checkbox('tags[]', 'code');
echo form_label('design', 'design');
echo form_checkbox('tags[]', 'design');
echo form_label('other', 'other');
echo form_checkbox('tags[]', 'other');
?>
</div>
</div>
控制器:
public function create()
{
$this->load->helper('form');
$this->load->library('form_validation');
$this->form_validation->set_rules('title', 'Title', 'trim|required');
$this->form_validation->set_rules('text', 'Text', 'trim|required');
if ($this->form_validation->run() === FALSE)
{
$this->load->view('admin/header', $data);
$this->load->view('admin/index', $data);
$this->load->view('admin/footer', $data);
}
else
{
$this->portfolio_model->set_project();
$this->load->view('admin/index', $data);
}
}
模型:
public function set_project()
{
$this->load->helper('url');
$slug = url_title($this->input->post('title'), 'dash', TRUE);
$data = array(
'title' => $this->input->post('title'),
'slug' => $slug,
'text' => $this->input->post('text'),
'url' => $this->input->post('url'),
'tags' => $this->input->post('tags')
);
return $this->db->insert('mydb', $data);
}
在数据库中显示“0的值”。 如何在同一个字段中显示3个值,如果他们都被检查?
任何帮助将不胜感激。谢谢
可能重复[如何将复选框值保存到MySQL数据库使用PHP](http://stackoverflow.com/questions/15341639/how-to-save-checkbox-value-into-mysql-database-using-php ) –