1
我有30多个用户输入的大表格,其中包括两个日期字段作为合同开始日期和合同结束日期。我正在使用Jquery UI在前端捕获日期。通过Codeigniter在MySQL中存储日期。存储为0000:00:00的日期
控制器:
$data = $this->input->post(); // returns all POST items without XSS filter
$this->form_validation->set_error_delimiters('<div class="alert alert-dismissible alert-info"><button type="button" class="close" data-dismiss="alert">close</button>', '</div>');
$this->form_validation->set_rules('nameMusicCompany', 'Music Company Name', 'required');
if($this->form_validation->run() == FALSE)
{
$this->load->view('pages/clientview/client_page');
$this->load->view('templates/footer');
}
else
{
$result = $this->client_model->create_new_client($data);
if($result !== false)
{
$this->session->set_flashdata('client_insert_message', '<div class="alert alert-success alert-dismissible text-center" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>New Client Created Successfully!</div>');
redirect('Client');
}
}
我已经使用$this->input->post()
获得阵列中的所有30个字段的值,并将其赋值给$的数据。
模型在MySQL表插入数据:
public function create_new_client($data)
{
$this->db->insert('client_data', $data);
if($this->db->affected_rows() > 0)
{
return true;
}
else
{
return false;
}
}
它的正常工作,除了日期存储为0000:00:00在表中。这两列的数据类型都是MySQL中的TIMESTAMP。