Jqueryui datepicker值未插入mysql表

时间:2014-11-07 00:03:21

标签: php jquery-ui-datepicker

所以我使用jqueryui datepicker..already将dateformat设置为mysql格式但遗憾的是它仍然不会插入到我的EventDate字段中..EventDate有一个Date数据类型..

<script>
$(function() {
   $( "#datepicker" ).datepicker({
  dateformat: "yyyy-mm-dd",
  changeMonth: true,
  changeYear: true
});}); </script>

我的提交可能有问题吗?

<form role="form" action='' method='POST'>
  <div class="form-group"><br><br><br>
   <p>Event Title:<input type='text' name='EventTitle' class="form-control col-md-offset-4" value='<?php if(isset($error)){ echo $_POST['eventTitle'];}?>'></p>
   <p>Date: <input name="datepicker" class="form-control col-md-offset-4" type="text" id="datepicker"></p>
   <input type="submit" name="submitevent" class="btn btn-primary  col-md-offset-4 "value="Submit Event"><br><br/>
   <a href="/sics/users/MainPanel.php"><input type='button' class="btn btn-primary  col-md-offset-4 " value='Back'></a>
</form>

也许是submitevent.php?

<?php

//if form has been submitted process it
if(isset($_POST['submitevent'])){

    //collect form data
    extract($_POST);

    //very basic validation
    if($EventTitle ==''){
        $error[] = 'Please enter the title.';
    }

    if($datepicker ==''){
        $error[] = 'Please enter the description.';
    }



    if(!isset($error)){

        try {



            //insert into database
            $stmt = $db->prepare('INSERT INTO events (EventName,EventDate) VALUES (:EventTitle, :EventDate)') ;
            $stmt->execute(array(
                ':EventTitle' => $EventTitle,
                ':EventDate' => $datepicker

            ));

            //redirect to MainPanel page
            header('Location: ../users/MainPanel.php');
            exit;

        } catch(PDOException $e) {
            echo $e->getMessage();
        }

    }

}?>

1 个答案:

答案 0 :(得分:0)

日期格式应为dateFormat : 'yy-mm-dd'

查看http://api.jqueryui.com/datepicker/