RonKevinT.Manuela 0 Junior Poster in Training

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

    }

}?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.