2

I am having trouble in saving an event to my database. Honestly, I have no idea what to do. I am able to show events in full calendar saved in phpmyadmin but my problem is how to save an event from full calendar.

<!DOCTYPE html>
 <html>
 <head>
  <meta charset='utf-8' />
  <link href='css/fullcalendar.css' rel='stylesheet' />
  <link href='css/fullcalendar.print.css' rel='stylesheet' media='print' />
  <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 calendar = $('#calendar').fullCalendar({
        editable: true,
        events:  "http://localhost/fullcalendar/events.php",

        //what goes here? :(
    });     
 });

</script>
<style>

body {
    margin: 0;
    padding: 0;
    font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
    font-size: 14px;
}

#calendar {
    width: 900px;
    margin: 40px auto;
}

</style>
</head>
<body>
<div id='calendar'></div>
</body>
</html>
brasofilo
  • 25,496
  • 15
  • 91
  • 179
Bryan Apilada
  • 31
  • 2
  • 6
  • possible duplicate of [fullCalendar events post method to php mysql](http://stackoverflow.com/questions/13338817/fullcalendar-events-post-method-to-php-mysql) – Farkhat Mikhalko Sep 13 '14 at 11:59
  • use full calendar v2.1 you are using old version. – Anup Sep 15 '14 at 10:10
  • @Anup Im using the v2.1 the problem is I don't know how to use it and save events. :( I'm a total newbie man and I need someone to teach me. :( – Bryan Apilada Sep 15 '14 at 11:25

2 Answers2

1

You have to make an ajax call.

for instance:

var title = event.title;
            var start = event.start.format();
            var end = (event.end == null) ? start : event.end.format();
            $.ajax({
                url: 'process.php',
                data: 'type=newtitle&title='+title+'&start='+start+'&end='+end+'&eventid='+event.id,
                type: 'POST',
                dataType: 'json',
                success: function(response){
                    if(response.status != 'success')                            
                    revertFunc();
                },......

and in your php file,you can each object:

$type = $_POST['type'];

if($type == 'newtitle')
{

    $title = $_POST['title'];
    $insert = mysqli_query($con,"INSERT INTO mytable(`title`) VALUES('$title')");
    $lastid = mysqli_insert_id($con);
    echo json_encode(array('status'=>'success','eventid'=>$lastid));
}
RileyManda
  • 2,536
  • 25
  • 30
-1
var s ="[{'title':1,'description':'Test1','start':'2014-09-15 16:00:00'}]";
        var myObject = eval('(' + s + ')');

        $('#CalContainer').fullCalendar(
        {
            defaultView : 'aWeek',
            slotEventOverlap : false,
            weekends : true,
            allDaySlot : false,
            firstDay:1,
            minTime:"06:00:00",
            maxTime:"24:00:00",
            forceEventDuration:true,
            defaultTimedEventDuration:"01:00:00",
            contentHeight : "400px",
            events:myObject,

            eventClick: function(calEvent, jsEvent, view) 


    {
alert(calEvent);
}
});
Anup
  • 3,283
  • 1
  • 28
  • 37
  • So where will I place this sir? I'm sorry for being dumb at this. :( I tried placing it at the part where I commented, "what goes here?" but nothing appeared I mean the calendar went gone. :( – Bryan Apilada Sep 15 '14 at 12:53
  • in your js file , also with events:myObjects, ........... in that you store events in an array form, do with this function and did you create div's in your html what is the exact problem only event showing or any other – Anup Sep 15 '14 at 12:58
  • I am able to show the events I stored in phpmyadmin sir. Now I wanted to move forward with this project and I wanted to know how can I add an event by clicking on a day and asking for an event title and saving it on the database. :( – Bryan Apilada Sep 15 '14 at 13:01
  • This is not an example of how to *save* an event. It is an example of how to *load* an event from a variable. If you want to save an event, it has to go back to json or a database somewhere. – bgmCoder Dec 30 '14 at 02:02