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 ) –