我的框架是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>
这是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))
在数据库中,“demo”的数据类型是datetime。数据库是mysql
答案 0 :(得分: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))
我没有看到您的任何输入日期。所以我添加到你的代码中。请试试。