dtgj8529 2016-01-14 16:48
浏览 87
已采纳

JS Fullcalendar更新数据库

I'm using full calendar js and I am able to connect the events created into the database using phpmyadmin however it does not update the database. Here is the codes:

<link href='css/fullcalendar.css' rel='stylesheet' />
<script src='js/moment.min.js'></script>
<script src='js/jquery.min.js'></script>
<script src='js/fullcalendar.min.js'></script>
<script>

 $(document).ready(function() {
  var date = new Date();
  var d = date.getDate();
  var m = date.getMonth();
  var y = date.getFullYear();

  var calendar = $('#calendar').fullCalendar({
   editable: true,
   header: {
    left: 'prev,next today',
    center: 'title',
    right: 'month,agendaWeek,agendaDay'
   },

   events: "calendarevents.php",

   // Convert the allDay from string to boolean
   eventRender: function(event, element, view) {
    if (event.allDay === 'true') {
     event.allDay = true;
    } else {
     event.allDay = false;
    }
   },
   selectable: true,
   selectHelper: true,
   select: function(start, end, allDay) {
   var title = prompt('Event Title:');
   var url = prompt('Type Event url, if exits:');
   if (title) {
       var start = $.fullCalendar.moment(start).format();
         var end = $.fullCalendar.moment(end).format();
   $.ajax({
   url: 'calendaraddevents.php',
   data: 'title='+ title+'&start='+ start +'&end='+ end +'&url='+ url ,
   type: "POST",
   success: function(json) {
   alert('Added Successfully');
   }
   });
   calendar.fullCalendar('renderEvent',
   {
   title: title,
   start: start,
   end: end,
   allDay: allDay
   },
   true // make the event "stick"
   );
   }
   calendar.fullCalendar('unselect');
   },

   editable: true,
   eventDrop: function(event, delta) {
   var start = $.fullCalendar.moment(start).format();
   var end = $.fullCalendar.moment(end).format();
   $.ajax({
   url: 'calendarupdateevents.php',
   data: 'title=' + event.title + '&start='+ start +'&end=' + end + '&id=' + event.id ,
   type: "POST",
   success: function(json) {   
    alert("Updated Successfully");
   }
   });
   },
   eventResize: function(event) {
   var start = $.fullCalendar.moment(start).format();
   var end = $.fullCalendar.moment(end).format();
   $.ajax({
    url: 'calendarupdateevents.php',
    data: 'title=' + event.title + '&start=' + start + '&end=' + end + '&id=' + event.id ,
    type: "POST",
    success: function(json) {
     alert("Updated Successfully");
    }
   });

}

  });

 }); 
</script>

Here is the codes for calendarupdateevents.php

<?php
/* Values received via ajax */
$id = $_POST['id'];
$title = $_POST['title'];
$start = $_POST['start'];
$end = $_POST['end'];

// connection to the database
try {
    $bdd = new PDO('mysql:host=localhost;dbname=ththy', 'calendar', '1234');
} catch(Exception $e) {
    exit('Unable to connect to database.');
}
// update the records
$sql = "UPDATE evenement SET title=?, start=?, end=? WHERE id=?";
$q = $bdd->prepare($sql);
$q->execute();
?>
  • 写回答

2条回答 默认 最新

  • dousi0144 2016-01-20 15:21
    关注

    As halfer said, you aren't passing any parameters to your query. Try this :

    <?php
    /* Values received via ajax */
    $values = array(
        'id' => int($_POST['id']),
        'title' => htmlentities($_POST['title'], ENT_QUOTES | ENT_IGNORE, "UTF-8"),
        'start' => htmlentities($_POST['start'], ENT_QUOTES | ENT_IGNORE, "UTF-8"),
        'end' => htmlentities($_POST['end'], ENT_QUOTES | ENT_IGNORE, "UTF-8")
    );
    // connection to the database
    try {
        $bdd = new PDO('mysql:host=localhost;dbname=ththy', 'calendar', '1234');
    } catch(Exception $e) {
        exit('Unable to connect to database.');
    }
    // update the records
    $sql = "UPDATE evenement SET title=?, start=?, end=? WHERE id=?";
    $q = $bdd->prepare($sql);
    $q->execute($values);
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!