dongque4778
dongque4778
2014-11-07 00:03
浏览 54
已采纳

Jqueryui datepicker值未插入mysql表

So Im using jqueryui datepicker..already set the dateformat to mysql format but sadly it still won't insert into my EventDate field..EventDate has a Date datatype..

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

Maybe there's something wrong with my submit?

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

Maybe 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();
        }

    }

}?>

图片转代码服务由CSDN问答提供 功能建议

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

 &lt; script&gt; 
 $(function(){
 $(“#datepicker”)。datepicker({  
 dateformat:“yyyy-mm-dd”,
 changeMonth:true,
 changeYear:true 
});});  &lt; / script&gt; 
   
 
 

我的提交可能有问题吗?

 &lt; form role =“ 表格“action =''method ='POST'&gt; 
&lt; div class =”form-group“&gt;&lt; br&gt;&lt; br&gt;&lt; br&gt; 
&lt; p&gt;事件标题:&lt;  input type ='text'name ='EventTitle'class =“form-control col-md-offset-4”value ='&lt;?php if(isset($ error)){echo $ _POST ['eventTitle'];  }&gt;'&gt;&lt; / p&gt; 
&lt; p&gt;日期:&lt; input name =“datepicker”class =“form-control col-md-offset-4”type =“text”id =“  datepicker“&gt;&lt; / p&gt; 
&lt; input type =”submit“name =”submitevent“class =”btn btn-primary col-md-offset-4“value =”Submit Event“&gt;&lt; br&gt;  ;&lt; br /&gt; 
&lt; a href =“/ sics / users / MainPanel.php”&gt;&lt; input type ='button'class =“btn btn-primary col-md-offset-4”value  ='返回'&gt;&lt; / a&gt; 
&lt; / form&gt; 
   
 
 

可能是submitevent.php?

  &lt;?php 
 
 //如果表单已经提交,请处理它
if(isset($ _ POST ['submitevent'])){
 
 //收集表单数据
extrac  t($ _ POST); 
 
 //非常基本的验证
 if($ EventTitle ==''){
 $ error [] ='请输入标题。'; 
} 
 
如果 ($ datepicker ==''){
 $ error [] ='请输入说明。'; 
} 
 
 
 
 if(!isset($ error)){
 
尝试 {
 
 
 
 //插入数据库
 $ stmt = $ db-&gt; prepare('INSERT INTO events(EventName,EventDate)VALUES(:EventTitle,:EventDate)'); 
 $ stmt  - &gt; execute(array(
':EventTitle'=&gt;  $ EventTitle,
':EventDate'=&gt;  $ datepicker 
 
)); 
 
 //重定向到MainPanel页面
标题('Location:../ users / MainPanel.php'); 
 exit; 
 
}} catch(PDOException $  e){
 echo $ e-&gt; getMessage(); 
} 
 
} 
 
}?&gt; 
   
 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongshungai4857
    dongshungai4857 2014-11-07 03:36
    已采纳

    The date format should be dateFormat : 'yy-mm-dd'

    Check out http://api.jqueryui.com/datepicker/

    点赞 评论

相关推荐