2017-08-09 14 views
-1

我的框架是codeigniter。我開發了一個表單來存儲用戶在數據庫中的輸入。一個輸入用於在輸入框內自動填充日期和時間。但是,當我嘗試將其保存在數據庫中時,日期不會保存。形式的其它值保存在數據庫 這是笨視圖頁自動時間不保存在數據庫中-codeigniter

<?php $attributes = array("name" => "addclients");echo form_open("home/ExpenseSave", $attributes);?>  
    <div class="row"> 
      <body onload="myFunction()"> 
      <input type="text" id="demo" class="form-control"/> 
    </div> 
    <script> 
function myFunction() { 

$(document).ready(function(){ 
    $('#demo').attr("placeholder", Date()); 
}); 

} 
</script> 

這在數據庫

$data = array(
       'demo'      => $this->input->post('demo'), 
       'pt'      => $this->input->post('pt'), 
       'pn'      => $this->input->post('pn'), 
       'task'      => $this->input->post('task'), 
       'employee'      => $this->input->post('employee'), 
       'projectname' => $this->input->post('projectname'), 
       'ExpenseName' => $this->input->post('ExpenseName'), 
       'ExpenseAmount' => $this->input->post('ExpenseAmount'), 

      ); 

      if ($this->db->insert('expenses', $data)) 

在數據庫中,數據類型爲「演示」保存數據這是笨控制器頁面是約會時間。數據庫爲MySQL

+0

請提供您的問題的完整信息。 – Nere

+0

@AbuHassan我編輯了我的問題 – Dushee

回答

1

在您的看法:

<?php $attributes = array("name" => "addclients");echo form_open("home/ExpenseSave", $attributes);?>  
    <div class="row"> 
      <body onload="myFunction()"> 
      <input type="text" name="current_date" class="form-control" value="<?php echo date('Y-m-d H:i:s') ?>" /> 
      <input type="text" id="demo" class="form-control"/> 
    </div> 
    <script> 
function myFunction() { 

$(document).ready(function(){ 
    $('#demo').attr("placeholder", Date()); 
}); 

} 
</script> 

而在你的模型:

$data = array(
       'demo'      => $this->input->post('demo'), 
       'pt'      => $this->input->post('pt'), 
       'pn'      => $this->input->post('pn'), 
       'task'      => $this->input->post('task'), 
       'employee'      => $this->input->post('employee'), 
       'projectname' => $this->input->post('projectname'), 
       'ExpenseName' => $this->input->post('ExpenseName'), 
       'ExpenseAmount' => $this->input->post('ExpenseAmount'), 
       'columnDate' => $this->input->post('current_date') 

      ); 

      if ($this->db->insert('expenses', $data)) 

我還沒有看到任何你輸入的日期。所以我加入你的代碼。請嘗試。

+0

謝謝阿布......現在值保存在數據庫中。但是我怎麼能改變我的國家的時區? – Dushee

+0

請參閱 https://stackoverflow.com/questions/3792066/convert-utc-dates-to-local-time-in-php – Nere

相關問題