2015-10-15 88 views
0

我使用html5 datepicker,我通过使用角度mysql的ajax发送该值。我有表格日期,在发送错误,如果我选择12/01,mydata保存在mysql数据库像11/01 /。我不知道如何解决这个问题。我已经附上了我的代码,提前致谢。HTML 5 datepicker显示日期前一天,当以角度发送数据ajax时

HTML:

<div class="col-sm-3" style="margin-bottom:10px;"> 
      <input type="date" class="form-control" ng-model="date1" required> 
     </div> 

JAVASCRIPT:

$scope.submitForm = function(){ 
    //console.log(); 
    var url = 'ajax/movies-master.php?action=add_movies'; 
    var d1 = {'uname': this.theatername, 'moviename': this.moviename, 'date': this.date1, 'time': this.time1, 'price': this.price }; 
    console.log(this.date1); 
    console.log('<br/>'); 
    console.log(d1); 
    $http.post(url, d1 
    ).success(function(data, status, headers, config) { 
     console.log(data); 
     console.log(data); 
     if (data.msg != '') 
     { 
      $scope.msgs = data.msg; 
      $scope.init(); 
      $scope.cancelCreating(); 
     } 
     else 
     { 
      $scope.errors = data.error; 
      $scope.init(); 
     } 
    }).error(function(data, status) { // called asynchronously if an error occurs 
// or server returns response with an error status. 
     $scope.errors.push(status); 
    }); 
} 

PHP:

$data = json_decode(file_get_contents("php://input")); 
$date = mysql_real_escape_string($data->date); 

$query = mysql_query('INSERT INTO tablename (date) values ("' . $date . '")'); 

我保存日期这样的,但我的日期被降耗工作。

任何人都可以知道这一点,在此先感谢。

+0

你是什么日期列的类型?日期时间,时间戳,日期等? –

+0

我保留日期.... – Vijaykarthik

+0

您的专栏名称是日期,对不对?尝试使用'当你调用它。就像这个''... INSERT INTO tablename('date')values ...''因为日期是保留字。 –

回答

0

日期选取器总是给你日期是当前的日期..所以你需要添加+1与日期的前一天......这肯定会为你工作

+0

感谢您的回复如何添加此,对于时间也面临同样的问题我选择2PM其保存错误在MySQL数据库,但在JavaScript文件,如果我控制台,并检查我得到正确的价值。如何解决这个朋友 – Vijaykarthik