从boostrap datepicker插入日期到MySQL日期字段不起作用

时间:2017-06-16 01:29:05

标签: php mysql date datepicker bootstrap-datepicker

我已经尝试了很多可能的解决方案而且它不适合我。我有以下代码:

<div class="bootstrap-iso">
    <div class="container-fluid">
        <div class="row">
           <div class="col-md-6 col-sm-6 col-xs-12">
               <!-- datepicker code begins -->
               <div class="form-group"> <!-- Date input -->
                   <label class="control-label" for="date">Closing Date</label>
                   <input class="form-control" id="date" name="date" placeholder="YYYY-  MM-DD" type="date"/>
               </div>
           </div>
       </div>    
    </div>

然后我有以下内容:

<script>
    $(document).ready(function(){
        var date_input=$('input[name="date"]'); //our date input has the name "date"
        var container=$('.bootstrap-iso form').length>0 ? $('.bootstrap-iso form').parent() : "body";
        var options={
            format: 'yyyy-mm-dd',
            container: container,
            todayHighlight: true,
            autoclose: true,
        };
        date_input.datepicker(options);
    })
</script>

在我的班上,我有以下代码:

$newVacancy_stmt = $db->prepare('INSERT INTO vacancies (roleID, shortTitle, longTitle, roleDescription, roleResponsibilities, roleRequirements, createdBy, creationDate, publishDate, closeDate) VALUES (:roleID, :shortTitle, :longTitle, :roleDescription, :roleResponsibilities, :roleRequirements, :createdBy, NOW(), NOW(), ' . $closingDate . '))');

我将发布日期转换为:

$closingDate = date('Y-m-d', strtotime($_POST['date']));

然后我调用我的函数:

$addVacancy = addNewVacancyInternal($roleID, $shortTitle, $longTitle, $roleDescription, $roleResponsibilities, $roleRequirements, $createdBy, $closingDate);

它不会将记录插入数据库。我一拿出日期(不插入日期)就插入记录。有什么建议吗?

1 个答案:

答案 0 :(得分:1)

$db->prepare('INSERT INTO vacancies (roleID, ...., publishDate, closeDate) 
                             VALUES (:roleID, .... NOW(), :closingDate))');

并将$closingDate与其他命名参数一起传递。