title: I am trying to insert date and time in sql server using pdo in php
body: <p>I am getting date through javascript function and sending it to php but I am getting SQLSTATE[HY093]: Invalid parameter number: parameter was not defined.  how can I insert datetime easily.
  here is my code</p>
  
  <pre><code>&lt;div class="modal fade" id="add_new_event_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel1"&gt;
  &lt;div class="modal-dialog" role="document"&gt;
      &lt;div class="modal-content"&gt;
          &lt;div class="modal-header"&gt;
              &lt;button type="button" class="close" data-dismiss="modal" aria-label="Close"&gt;&lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;&lt;/button&gt;
              &lt;h4 class="modal-title" id="myModalLabel1"&gt;Add New Event&lt;/h4&gt;
          &lt;/div&gt;
          &lt;div class="modal-body"&gt;
              &lt;div class="form-group"&gt;
                  &lt;label for="first_name"&gt;Event Name&lt;/label&gt;
                  &lt;input type="text" id="event_name" name="event_name" placeholder="EventName" class="form-control"/&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label for="example-datetime-local-input"&gt;Date and time&lt;/label&gt;
                  &lt;div class="input-append date form_datetime" data-date=""&gt;
                      &lt;input size="16" type="text" value="" id="wedding_date" name="wedding_date" readonly class="form-control"&gt;
                      &lt;span class="add-on"&gt;&lt;i class="icon-remove"&gt;&lt;/i&gt;&lt;/span&gt;
                      &lt;span class="add-on"&gt;&lt;i class="icon-calendar"&gt;&lt;/i&gt;&lt;/span&gt;
                      &lt;script type="text/javascript"&gt;
                          $(".form_datetime").datetimepicker({
                          format: "dd mm yyyy hh:ii",
                          autoclose: true,
                          todayBtn: true,
                          startDate: "2017-01-14 10:00",
                          minuteStep: 10
                          });
                      &lt;/script&gt;            
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="modal-footer"&gt;
              &lt;button type="button" class="btn btn-default" data-dismiss="modal"&gt;Cancel&lt;/button&gt;
              &lt;button type="button" class="btn model-button" id="AddEvent" OnClick="addEvent()"&gt;Save Changes&lt;/button&gt;
          &lt;/div&gt;
  
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>My script here </p>
  
  <pre><code>function addEvent() 
  {
  
      var event_name = $("#event_name").val();
      var wedding_date = $("#wedding_date").val();
  
      // Add event
      $.post("ajax/addData.php", 
      {
          event_name: event_name,
          wedding_date: wedding_date
      }, 
      function (data, status) 
      {
          //console.log(data);
          // close the popup
  
          alert("Data: " + data + "\nStatus: " + status);
          $("#add_new_event_modal").modal("hide");
  
          // read records again
          readEvent();
  
          // clear fields from the popup
          $("#event_name").val("");
          $("#wedding_date").val("");
  
      });
  }
  </code></pre>
  
  <p>and my function</p>
  
  <pre><code>if (isset($_POST['event_name']) &amp;&amp; isset($_POST['wedding_date'])) 
  {
      $event_name = $_POST['event_name'];
      $wedding_date = $_POST['wedding_date'];
      //$category_name = $_POST['category_name'];
      $object = new crud();
      $object-&gt;addEvent($event_name, $wedding_date);
  }
  
      public function addEvent($event_name, $wedding_date)
      {
          try
          {
              $stmt = $this-&gt;DB_conn-&gt;prepare("INSERT INTO event1(event_name,  wedding_date)
                                                                VALUES(:event_name, :wedding_date)");
                  $stmt-&gt;bindparam(":eventname",$event_name);
                  $stmt-&gt;bindparam(":weddingdate",$wedding_date, PDO::PARAM_STR);
                  $stmt-&gt;execute(); 
          }   
          catch(PDOException $e)
          {
              echo $e-&gt;getMessage();
          }
  
      }
  </code></pre>