2017-08-09 13 views
-1

私のフレームワークはcodeigniterです。私はデータベースにユーザー入力を格納するためのフォームを開発しました。 1つの入力は、自動的に入力ボックス内に日付と時刻を入力します。しかし、データベースに保存しようとすると、日付は保存されません。フォーム内の他の値は、データベース に節約これは、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> 

これは、「デモ」のデータ型が、データベース内のデータベースにデータを保存CodeIgniterのコントローラページ

$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

ありがとうAbu..now値はデータベースに保存されます。しかし、どのように私の国にタイムゾーンを変更できますか? – Dushee

+0

https://stackoverflow.com/questions/3792066/convert-utc-dates-to-local-time-in-phpを参照してください。 – Nere

関連する問題