MySQL update works fine, but insert doesn't

Hi,

I’m running dhtmlxScheduler on a windows server with php installed. I’m not familiar with dhtmlxScheduler at all and I’m trying to set it up. I’m using a MySQL database, however when I try and set the script to recurring events I can only update/delete records in the database, I can’t add new recurring events.

I can add new events using the basic events settings, but for recurring events, it just won’t add. Am I missing something obvious here? All paths to all the files are correct, and I’m getting no errors, it’s just not saving any new recurring events I try to enter into the MySQL database.

Here’s my code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title></title>
</head>

<script src="codebase/dhtmlxscheduler.js?v=091201" type="text/javascript" charset="utf-8"></script>
<script src="codebase/ext/dhtmlxscheduler_year_view.js?v=091201" type="text/javascript" charset="utf-8"></script>
<script src="codebase/ext/dhtmlxscheduler_recurring.js" type="text/javascript" charset="utf-8"></script>

<link rel="stylesheet" href="codebase/dhtmlxscheduler.css" type="text/css" media="screen" title="no title" charset="utf-8">
<link rel="stylesheet" href="codebase/ext/dhtmlxscheduler_ext.css" type="text/css" title="no title" charset="utf-8">
<link rel="stylesheet" href="codebase/ext/dhtmlxscheduler_recurring.css" type="text/css" title="no title" charset="utf-8">

	
<style type="text/css" media="screen">
	html, body{
		margin:0px;
		padding:0px;
		height:100%;
		overflow:hidden;
	}
	.dhx_scale_holder_now.weekday, .dhx_scale_holder.weekday{
		background-image:url(common/week_bg.png);
	}
</style>

<script type="text/javascript" charset="utf-8">
	function init() {
		
		scheduler.config.xml_date="%Y-%m-%d %H:%i";
		scheduler.templates.week_date_class=function(date,today){
			if (date.getDay()==0 || date.getDay()==6)
				return "weekday";	
			return "";
		}
		scheduler.config.details_on_create=true;
		scheduler.config.details_on_dblclick=true;
		scheduler.init('scheduler_here',null,"week");
		scheduler.load("php/events_rec.php?uid="+scheduler.uid());
		var dp = new dataProcessor("php/events_rec.php");		
		dp.init(scheduler);
		
	}
</script>

<body onload="init();">
    <div id="scheduler_here" class="dhx_cal_container" style='width:100%; height:100%;'>
        <div class="dhx_cal_navline">
    
            <div class="dhx_cal_prev_button">&nbsp;</div>
            <div class="dhx_cal_next_button">&nbsp;</div>
            <div class="dhx_cal_today_button"></div>
            <div class="dhx_cal_date"></div>
            <div class="dhx_cal_tab" name="day_tab" style="right:332px;"></div>
            <div class="dhx_cal_tab" name="week_tab" style="right:268px;"></div>
            <div class="dhx_cal_tab" name="month_tab" style="right:204px;"></div>
            <div class="dhx_cal_tab" name="year_tab" style="right:140px;"></div>
    
        </div>
        <div class="dhx_cal_header">
        </div>
        <div class="dhx_cal_data">
        </div>		
    </div>
</body>
</html>

Any ideas?

Thanks

JS code looks fine.
Be sure that you are using correct DB structure

samples/common/dump_reccuring.sql
samples/03_extensions/php/events_rec.php

DB structure requires few additional events to support recurring events.

I’ve dropped and restored the tables numerous times. As far as I can see everything is as it should be, it all matches up. It will fetch and display the data in the ‘events_rec’ table just fine, it will let me edit existing records without a problem, it just won’t let me add.

If I try and add a recurring record it will let me and it will display my entry fine, but it’s never entered into the database so as soon as I refresh the calendar my entry isn’t there anymore. I can add regular events without a problem as I mentioned.

Here is the database structure for ‘events_rec’ as shown in MySQL Query Browser:

i39.tinypic.com/23u7mdd.jpg

Hope this helps?

You are using connector’s for server side, right ?

Can you provide a code snippet from server side file, where connector is configured?

By the way, DB scheme looks correct as well.

Hi,

Thanks for your help again Stanislav, and yes I’m using server side.

I haven’t touched any of the PHP code other than the config.php file, see below:

<?php $server = "192.168.111.16"; $user = "root"; $pass = "mypassword"; $db_name= "intranet"; ?>

I’m also using Dreamweaver CS4 which rather handily shows which files each page includes. I’ve checked and doubled checked each import for scheduler_connector.php to make sure they’re linked correctly, in turn I’ve opened each imported page and checked each import on those pages are correctly linked. There are no mislinked files (which I’m guessing could be the cause of this?).

I doubt the code snipped above is much use, but any other suggestions you or anyone else has would be greatly appreciated. It might also be worth mentioning that I’m running this on a windows machine with PHP installed, is there anything inparticular I should be looking for in the phpinfo page that might be preventing inserts (even though regular event inserts work fine)?

Also, if it’s not too much to ask, is there a way of logging PHP errors to maybe help understand where the underlying problem is?

Thanks again.

Code for connector’s initialization must look as

$scheduler->render_table("events_rec","event_id","start_date,end_date,text,rec_type,event_pid,event_length");

The list of fields, must contain all involved fields, same as in the above snippet

I haven’t touched any of the PHP code
There are few samples of server side integration, and not all of them can be used with recurring events. You can take as a base

samples\03_extensions\php\events_rec.php

$scheduler = new schedulerConnector($res); $scheduler->enable_log("log.txt",true); //error logging

Hi Stanislav,

Thanks for your help and sorry for the confusion. The list of fields contains all the involved fields and is identical to the one you posted.

I turned on error logging and I found the problem. The error log doesn’t return any errors but I took the insert commands for both a regular insert with no recurrence and an insert for a recurring event and tried to add them manually to the MySQL database.

It turns out ‘event_pid’ and ‘event_length’ must contain a value. When I try and manually submit the SQL inserts for both events:

INSERT INTO events_rec(start_date,end_date,text,rec_type,event_pid,event_length) VALUES ('2010-04-08 02:00','2010-04-08 08:10','TESTING','','','')
INSERT INTO events_rec(start_date,end_date,text,rec_type,event_pid,event_length) VALUES ('2010-04-01 06:15','9999-02-01 00:00','RECURRING TEST','month_1_1_1_#no','','12000')

I get the following error from MySQL:

Incorrect integer value: '' for column 'event_pid' at row 1

If I replace the blank ‘event_pid’ and ‘event_length’ values with a ‘0’ the insert works fine. I’ve tried changing the MySQL settings to have 0 as a default value for those fields but it makes no difference for some reason, perhaps it’s the version of MySQL I’m running? I’m not sure.

But if someone can tell me how to insert a ‘0’ into the ‘event_pid’ and ‘event_length’ fields should either be blank then this will sort the problem.

I’m not a PHP coder (hence PHP being installed on a windows server), I’m designing an internal intranet and the scheduler is the only part that will be running PHP.

Can anyone assist please?

Thanks

Next can be added to connector’s configuration ( before render_table or render_sql commands )

[code]function set_defaults($data){
$pid = $data->get_value(“event_pid”);
$length = $data->get_value(“event_length”);

  if ($length == "")
           $data->set_value("event_length","0");
  if ($pid == "")
           $data->set_value("event_pid","0");

}
$scheduler->event->attach(“beforeProcessing”, “set_defaults”);[/code]