Connecting to database and saving data

Hi all,

I’m having problems connecting to mysql and saving any data inserted from the scheduler to the database.

This is my html code which i rename as calendarhp.html:

<html>

<head>

<title>Home</title>

<link href="http://bit-mp.tp.edu.sg/~m02/codebase/dhtmlxscheduler.css" rel="stylesheet" type="text/css"/>

<script type="text/javascript" src="http://bit-mp.tp.edu.sg/~m02/codebase/dhtmlxscheduler.js"></script>



</head>

<style type="text/css" media="screen">
 html, body{
 margin:0px;
 padding:0px;
 height:100%;
 overflow:hidden;
}
</style>

<body>

<div id="scheduler_here" class="dhx_cal_container" style="width:100%; height:100%;">
<div class="dhx_cal_navline">
<div class="dhx_cal_prev_button"> </div>
<div class="dhx_cal_next_button"> </div>
<div class="dhx_cal_today_button"></div>
<div class="dhx_cal_date"></div>
<div class="dhx_cal_tab" name="day_tab" style="right:204px;"></div>
<div class="dhx_cal_tab" name="week_tab" style="right:140px;"></div>
<div class="dhx_cal_tab" name="month_tab" style="right:76px;"></div>
</div>

<div class="dhx_cal_header"></div>
<div class="dhx_cal_data"></div>
</div>

<script type="text/javascript" charset="utf-8">
scheduler.init('scheduler_here', new Date(), "month");
scheduler.load("calendarevent.php");
 
var dp = new dataProcessor("calendarevent.php");
dp.init(scheduler);

var events = [
{id:1, text:"Meeting", start_date:"04/11/2013 14:00",end_date:"04/11/2013 17:00"},
{id:2, text:"Conference",start_date:"04/15/2013 12:00",end_date:"04/18/2013 19:00"},
{id:3, text:"Interview", start_date:"04/24/2013 09:00",end_date:"04/24/2013 10:00"}
];
scheduler.parse("events", "json");//takes the name and format of the data source
</script>

</body>

</html>

and this is my events.php which i rename as calendarevent.php code:

<?php
	include ('http://bit-mp.tp.edu.sg/~m02/codebase/scheduler_connector.php');

    $res=mysql_connect($mysql_server,$mysql_user,$mysql_pass); 
    mysql_select_db($mysql_db); 
	
	$scheduler = new schedulerConnector($res);
	//$scheduler->enable_log("log.txt",true);
	$scheduler->render_table("2_Calendar","id","start_date,end_date,text");
?>

I’m completely new to php, would really appreciate any help. Thank you in advance!

Hello,

  1. make sure you’ve enabled autoincrement for ‘id’ column. Otherwise connector won’t be able to insert new item
  2. On the client side, you either need to load events from the database or add them to the scheduler using addEvent. If you parse event from json (and event with such id does not exists in the database), scheduler won’t be able to save it because it will be trying to perform ‘update’ for the item which not exists in database.

If none of this helps - try enabling the log and check what the error message is

docs.dhtmlx.com/scheduler/api__s … _load.html

Thanks for the reply i really appreciated it :slight_smile:

However, I still can’t make it work to load data and save data to mysql.
Particularly I need to save data to my database when users enter data from the lightbox and the calendar will load data from the database to display the events.

Here is my updated code:

<html>

<head>

<title>Home</title>

<link href="http://bit-mp.tp.edu.sg/~m02/codebase/dhtmlxscheduler.css" rel="stylesheet" type="text/css"/>

<script type="text/javascript" src="http://bit-mp.tp.edu.sg/~m02/codebase/dhtmlxscheduler.js"></script>



</head>

<style type="text/css" media="screen">
 html, body{
 margin:0px;
 padding:0px;
 height:100%;
 overflow:hidden;
}
</style>

<body>

<div id="scheduler_here" class="dhx_cal_container" style="width:100%; height:100%;">
<div class="dhx_cal_navline">
<div class="dhx_cal_prev_button"> </div>
<div class="dhx_cal_next_button"> </div>
<div class="dhx_cal_today_button"></div>
<div class="dhx_cal_date"></div>
<div class="dhx_cal_tab" name="day_tab" style="right:204px;"></div>
<div class="dhx_cal_tab" name="week_tab" style="right:140px;"></div>
<div class="dhx_cal_tab" name="month_tab" style="right:76px;"></div>
</div>

<div class="dhx_cal_header"></div>
<div class="dhx_cal_data"></div>
</div>

<script type="text/javascript" charset="utf-8">
scheduler.load("calendarevent.php");
scheduler.config.api_date="%Y-%m-%d %H:%i";
scheduler.init('scheduler_here', new Date(), "month");

scheduler.addEvent({
    id:2,
    start_date:"2014-10-25 15:00",
    end_date:"2014-10-25 19:00",
    text:"New event"
});

 var dp = new dataProcessor("http://bit-mp.tp.edu.sg/~m02/codebase/scheduler_connector.php");
dp.init(scheduler);

var events = [
{id:1, text:"meeting", start_date:"2014-10-23 22:37:20",end_date:"2014-10-23 22:45:00"},

];
scheduler.parse("events", "json");//takes the name and format of the data source
</script>

</body>

</html>

and my server side code:

<?php 
require_once('http://bit-mp.tp.edu.sg/~m02/codebase/scheduler_connector.php');
$res=mysql_connect("localhost","user","password");
mysql_select_db("m02");
$calendar = new SchedulerConnector($res);
$scheduler->enable_log("log.txt",true);
$calendar->render_table("2_Calendar","id","start_date,end_date,text");
?>

Hello,

var dp = new dataProcessor("http://bit-p.tp.edu.sg/~m02/codebase/scheduler_connector.php");
if http://bit-p.tp.edu.sg is not the same server where your app is hosted, then dataprocessor won’t be able to send updates there. It uses the regular Ajax request which does not work cross-domain.
You need either have processing logic on your server, or have some proxy handler that will receive ajax from dataprocessor, resend it to the remote server and return the remove response. In both cases php should be placed on the same domain where your page is.
Alternatively, you can trace changes in the scheduler and send changes to the server manually, using JSONP or any other approach for cross-domain requests.

require_once('http://bit-mp.tp.edu.sg/~m02/codebase/scheduler_connector.php'); Usually cross-domain includes and requires are disabled in php settings for security reasons
stackoverflow.com/questions/2752 … r-with-php

Hi Aliaksandr,

thank you your reply:)
I’m sure the app is under the same server and checked that there is any typo error in the file path for both the files but to no luck.
Would really appreciate your further help!

I’m sure the app is under the same server
It must be not only the same server, but the same domain name as well.

If you are loading page like “localhost/some.html”, while full server name is “bit-mp.tp.edu.sg” it will not allow to load data from such url. Browser checks only that domain of the page and domain of data feed is the same, it doesn’t really care is it the same server or not.