每当我在FullCalendar中的日视图中拖放事件时,我都会尝试更新数据库中的开始日期时间和结束日期时间。这是我的代码的一部分:
eventDrop: function(event){
var id = event.id;
var start = event.start;
var end = event.end;
var table = [id, start, end];
$.ajax({
url: '{{asset('bundles/ikprojhome/phptest/moslem16.php')}}',
type: 'POST',
data: {table: table},
});
}
顺便说一下,这是文件moslem16.php的代码:
<?php
$myArray = $_REQUEST['table'];
$a = $myArray[0];
$b = $myArray[1];
$c = $myArray[2];
$con=mysqli_connect("localhost","root","","wkayetdb");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"UPDATE eventsgroupe SET start='".$b."', end='".$c."' WHERE id='".$a."'");
mysqli_close($con);
?>
这就是表格的结构&#34; eventsgroupe&#34;在数据库中(字段的名称在左侧,其类型在右侧):
id:int(15)
title:varchar(255)
开始:日期时间
结束:日期时间
location:varchar(255)
描述:varchar(255)
admingroupe_id:int(20)
idgroupe:int(20)
partger:tinyint(1)
问题是,在日视图中拖放事件后,每个字段的值开始&#34;开始&#34;和领域&#34;结束&#34;在表格&#34; eventsgroupe&#34;成为以下一个:0000-00-00 00:00:00。 所以我的问题是:
答案 0 :(得分:0)
我解决了!!我更改了第一个代码如下:
eventDrop: function(event){
var id = event.id;
var start = event.start;
var end = event.end;
var startdate = [[start.getFullYear(), AddZero(start.getMonth() + 1), AddZero(start.getDate())].join("-"), [AddZero(start.getHours()), AddZero(start.getMinutes())].join(":"), start.getHours() >= 12 ? "PM" : "AM"].join(" ");
var enddate = [[end.getFullYear(), AddZero(end.getMonth() + 1), AddZero(end.getDate())].join("-"), [AddZero(end.getHours()), AddZero(end.getMinutes())].join(":"), end.getHours() >= 12 ? "PM" : "AM"].join(" ");
function AddZero(num) {
return (num >= 0 && num < 10) ? "0" + num : num + "";
}
var startdate1 = startdate.substring(0, startdate.length - 3) + ":00";
var enddate1 = enddate.substring(0, enddate.length - 3) + ":00";
var table = [id, startdate1, enddate1];
$.ajax({
url: '{{asset('bundles/ikprojhome/phptest/moslem16.php')}}',
type: 'POST',
data: {table: table},
});
}
我改变了第二个代码如下:
<?php
$myArray = $_REQUEST['table'];
$a = $myArray[0];
$b = $myArray[1];
$c = $myArray[2];
$con=mysqli_connect("localhost","root","","wkayetdb");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"UPDATE eventsgroupe SET start='".$b."', end='".$c."' WHERE id='".$a."'");
mysqli_close($con);
?>
现在它正常工作!!