2014-11-07 81 views
1

因此,進出口..jQueryUI的日期選擇器值不插入MySQL表

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

    } 

}?> 

回答

相關問題