How to store selected datepicker javascript using PHP -


i need badly form task. when had selected date such 2015-05-08 stored 1970-01-01. had tried solutions found still can't work well.

below codes. hope guys can help. appreciate it.

php files

<div id = "wrapper">     <div id = "page1">     <div class="title">       <h3>check-in / check-out date</h3></div>         <div class = "container">             <div style="padding: 10px 50px 0 20px; ">                         <table align="center" class="bookingform" style="color: #000;">                            <tr>                             <td>check-in date:</td>                             <td><input id="cid" type="text"  name="cid" onchange="checknight()"></td>                            </tr>                            <tr>                             <td>check-out date:</td>                             <td><input id="cod" type="text"  name="cod" onchange="checknight()"></td>                            </tr>                            <tr>                             <td>no. of night:</td>                             <td><input id="night" type="text" value="0" name="night"></td>                            </tr>                            <tr>                              <td></td>                              <td><input type="button" value="next" name="nextbutton" id="nextbutton" class="nextbutton" onclick="next()" >                                  <input type="hidden" id="noroom" style="display:none;" value="1">                              </td>                            </tr> 

javascript code

$(document).ready(function() {         $("#cid").datepicker({             dateformat: "yy-mm-dd",             mindate: 0,             onselect: function(date) {                 var date2 = $('#cid').datepicker('getdate');                 date2.setdate(date2.getdate() + 1);                 //sets mindate dt1 date + 1                 $('#cod').datepicker('option', 'mindate', date2);                 checknight();             }         });         $('#cod').datepicker({             dateformat: "yy-mm-dd",             onclose: function() {                     var dt1 = $('#cid').datepicker('getdate');                     var dt2 = $('#cod').datepicker('getdate');                     //check prevent user entering date below date of dt1                     if (dt2 <= dt1) {                         var mindate = $('#cod').datepicker('option', 'mindate');                         $('#cod').datepicker('setdate', mindate);                         checknight();                     }                 }         });     });      function checknight() {         var dateget = new date;         var dateget2 = new date;          dateget = $('#cid').datepicker("getdate");         dateget2 = $('#cod').datepicker("getdate");           if ($('#cid').val() != "" && $('#cod').val() != "") {            var diffday = math.abs(dateget2 - dateget);            diffday = diffday / 86400000;            if(diffday<0){             }else{                 document.getelementbyid('night').value = diffday;             }           }         }      function next(){         var cid = $("#cid").val();         var cod = $("#cod").val();         var night = $("#night").val();         //if cid , cod empty         if(cid == "" || cod == ""){             alert('please key in required field');         }         //redirect next page if fuifil requirement         else{             window.location="http://localhost/reserve/app/room.php";         }     } 

storing date code

<?php $cid = $_post['cid']; $ciddate = date('ymd', strtotime($cid));     $cod = $_post['cod']; $coddate = date('ymd', strtotime($cod)); $night = $_post['night'];  $sql = ("insert `check`(`cid`, `cod`, `night`) values ('$ciddate','$coddate','$night')"); 

?> ?>

this not right way it.
should use form in html.
after can chose if want send variable through action attribute of form
(ex: "<form action="page.php" method="php">)
or can directly in jquery
(ex: $('.nextbutton).on("click", function(){
$.post( "page.php", { param1: "<value1>", param2: "value2" } );
});


Comments