2016-04-05 164 views
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">&times;</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。

回答

1

mysql timestamp field accept yyyy-mm-dd H:i:s日期的格式,所以你必须将日期传递到这种格式,而不是UNIX时间戳。

转换的日期是这样的:

$date = date('Y-m-d H:i:s', $your_date); 
相关问题