fullCalendar events post method to MySQL

前提是你 提交于 2019-11-29 02:29:46
Daniel Sloan Johnson

This is the conclusion I have come up with and I have no problem running this off my test and public server. I have taken the FullCalendar and this is the format I use.

The database is real simple.

id integer 11 chars primary key auto-increment,
title varchar 50,
start varchar 50,
end varchar 50,
url varchar 50.

This is the index.php or index.html file.

<!DOCTYPE html>
<html>
<head>
<link href='css/fullcalendar.css' rel='stylesheet' />
<link href='css/fullcalendar.print.css' rel='stylesheet' media='print' />
<script src='js/jquery-1.9.1.min.js'></script>
<script src='js/jquery-ui-1.10.2.custom.min.js'></script>
<script src='js/fullcalendar.min.js'></script>
<script>
    $(document).ready(function() {
        $('#calendar').fullCalendar({
            header: {
                left: 'prev,next today',
                center: 'title',
                right: 'month,agendaWeek,agendaDay'
            },
            editable: true,
            events: "json.php",
            eventDrop: function(event, delta) {
                alert(event.title + ' was moved ' + delta + ' days\n' +
                    '(should probably update your database)');
            },
            loading: function(bool) {
                if (bool) $('#loading').show();
                else $('#loading').hide();
            }
        });
    });
</script>
<style>
    body {
        margin-top: 40px;
        text-align: center;
        font-size: 14px;
        font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
        } 
    #loading {
        position: absolute;
        top: 5px;
        right: 5px;
        }
    #calendar {
        width: 900px;
        margin: 0 auto;
        } 
</style>
</head>
<body>
<div id='loading' style='display:none'>loading...</div>
<div id='calendar'></div>
<p>json.php needs to be running in the same directory.</p>
</body>
</html>

This is the json.php file.

<?php
mysql_pconnect("localhost", "root", "") or die("Could not connect");
mysql_select_db("calendar") or die("Could not select database");


$rs = mysql_query("SELECT * FROM events ORDER BY start ASC");
$arr = array();

while($obj = mysql_fetch_object($rs)) {
$arr[] = $obj;
}
echo json_encode($arr);
?>

Once remove the column names in insert query and try, if you don't get then let's think about it. Do something like this

mysql_query(INSERT INTO `events` VALUES ('$id', '$title', '$start', '$end', ''));

Just print the post values before inserting, if it seems clear, then check your query.

echo the query and exit, you may get something like this

mysql_query(INSERT INTO `events` VALUES ('23', 'event title', 'start date', 'end date', ''));

Run this query to find errors if any

marc

print $query - there should be a ; at the end

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!