2017-06-16 67 views
0

我已經嘗試了很多可能的解決方案,它只是不適合我。我有以下代碼:從boostrap datepicker插入日期到MySQL日期字段不起作用

<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> 

然後我有follownig:

<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); 

它不會將記錄插入數據庫。只要我將日期取出(不插入日期),它就會插入記錄。有什麼建議嗎?

+0

檢查您在$ _POST ['date']中獲得的值。告訴我們價值。 – Sehdev

回答

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

並通過$closingDate與其餘的命名參數。

+0

'$ closingDate = date('Ym-d',strtotime($ _ POST ['date']));' – Willem

+0

'$ addVacancy = addNewVacancyInternal($ roleID,$ shortTitle,$ longTitle,$ roleDescription,$ roleResponsibilities,$ roleRequirements ,$ createdBy,$ closingDate);''$ 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))'';' – Willem

+0

'$ newVacancy_stmt-> bindParam(':closingDate',$ closingDate,PDO :: PARAM_STR);''$ addNewVacancy = $ newVacancy_stmt-> execute();'仍然沒有工作謝謝。 – Willem