【发布时间】:2015-10-15 07:42:34
【问题描述】:
我正在使用 html5 datepicker,我正在使用 angular mysql 通过 ajax 发送该值。我有表格日期,如果我选择 12/01,则发送错误,mydata 保存在 mysql 数据库中,如 11/01/。我不知道如何解决这个问题。我在下面附上了我的代码,提前致谢。
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 . '")');
我正在这样保存日期,但我的日期正在保存工作。
有人知道吗,先谢谢了。
【问题讨论】:
-
你的日期栏是什么类型的?日期时间、时间戳、日期等?
-
您的栏目名称是日期,对吗?调用时尝试使用`。喜欢这个
...INSERT INTO tablename (`date`) values...,因为日期是保留字。
标签: javascript php mysql angularjs