Updating and Inserting at the same time Problem

I have a problem with a Form when I try to update it seems to perform the update but right after updating is also inserting the same data and duplicates it.

I have trying to solve it with setting the transaction mode in GET because in the debugging process I can observe the GET updates and then a POST inserts the same data again.

the output of the log is:

Log started, 13/08/2014 07:08:16

While there is no edit mode mark, POST parameters similar to edit mode detected. \n Switching to edit mode ( to disable behavior remove POST[ids]

DataProcessor object initialized
27_nombre => Modificado 22 19
27_lat => 15.505833394197783
27_lgn => -88.02682757377625
27_clienteID => 3
27_!nativeeditor_status => updated
1407930164039_nombre => Modificado 22 19
1407930164039_lat => 15.505833394197783
1407930164039_lgn => -88.02682757377625
1407930164039_clienteID => 3
1407930164039_!nativeeditor_status => inserted
ids => 27,1407930164039

Row data [27]
nombre => Modificado 22 19
lat => 15.505833394197783
lgn => -88.02682757377625
clienteID => 3
!nativeeditor_status => updated

UPDATE geofence SET clienteID=‘3’,nombre=‘Modificado 22 19’,lat=‘15.505833394197783’,lgn=‘-88.02682757377625’ WHERE geoID=‘27’ AND (geoID = ‘27’)

Row data [1407930164039]
nombre => Modificado 22 19
lat => 15.505833394197783
lgn => -88.02682757377625
clienteID => 3
!nativeeditor_status => inserted

INSERT INTO geofence(clienteID,nombre,lat,lgn) VALUES (‘3’,‘Modificado 22 19’,‘15.505833394197783’,‘-88.02682757377625’)

Edit operation finished
0 => action:updated; sid:27; tid:27;
1 => action:inserted; sid:1407930164039; tid:29;

Done in 0.0072581768035889s

date(): It is not safe to rely on the system’s timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘America/New_York’ for ‘EDT/-4.0/DST’ instead at /var/www/vhosts/g4smobile.com/httpdocs/classes/codebase/tools.php line 267

====================================

the PHP connector is: guarda_geofence.php

[code]<?php
require_once(“…/conf/config.php”);

$res=mysql_connect($mysql_server,$mysql_user,$mysql_pass);
mysql_select_db($mysql_db);

require("../classes/codebase/form_connector.php");

$Formconn = new FormConnector($res,"MySQL");
$Formconn->set_encoding("iso-8859-1");
$Formconn->enable_log("../log.txt",true);

$Formconn->render_table("geofence","geoID","clienteID,nombre,lat,lgn"); 

?>[/code]

And the form code is:

[code]function winMntGeofence(selId){
var geocoder;
var geoInfowindow = new google.maps.InfoWindow();
var geoMarker = null;
var fence = {};

        geocoder = new google.maps.Geocoder();
        var myGeoLatlngld;
        var geoMapOptionsld;
        var GeofenceMaps;
        
        var dhxWins = new dhtmlXWindows();
        dhxWins.enableAutoViewport(false);
        dhxWins.attachViewportTo("parentId");
        dhxWins.setImagePath("classes/codebase/imgs/");
        
        var w1 = dhxWins.createWindow("w1", 20, 5, 1200, 440);
        w1.setText("Editar Geofence de Cliente");
        w1.setModal(true);
        w1.center();  
        
        var geoLayout = w1.attachLayout("2U");
        geoLayout.cells("a").hideHeader();
        geoLayout.cells("b").hideHeader();
        
        var vwFrmClnt = geoLayout.cells("b").attachForm(addGeofenceClientFrm);
                 
        vwFrmClnt.load("connectors/guarda_geofence.php?id="+selId,function(id, response){
            vwFrmClnt.setItemLabel("_geofence","Geofence No. "+selId);
            myGeoLatlngld = new google.maps.LatLng(vwFrmClnt.getItemValue("lat"), vwFrmClnt.getItemValue("lgn"));
            geoMapOptionsld = {
            zoom: 16,
            center: myGeoLatlngld,
            mapTypeId: google.maps.MapTypeId.ROADMAP };
            fence["fence"] = {
              center: new google.maps.LatLng(vwFrmClnt.getItemValue("lat"), vwFrmClnt.getItemValue("lgn")),
            };
            GeofenceMaps = geoLayout.cells("a").attachMap(geoMapOptionsld);
        });
        
        //Dataprocessor 
                    
        var dpfgeofence = new dataProcessor("connectors/guarda_geofence.php?id="+selId);
        dpfgeofence.setTransactionMode("GET");
        dpfgeofence.init(vwFrmClnt);
        
        vwFrmClnt.attachEvent("onButtonClick", function(id){
            if (id=='saveButton'){
                vwFrmClnt.save();
            }else if (id=='closeButton'){
                w1.close();
            }
        });
        
        dpfgeofence.attachEvent("onAfterUpdateFinish",function(){
                cargaGeofences();
                w1.close();
            });
        
        //Ends Dataprocessor
                  
        if(navigator.geolocation)
        {
            navigator.geolocation.getCurrentPosition(function(position) {
            var geoPos = new google.maps.LatLng(vwFrmClnt.getItemValue("lat"), vwFrmClnt.getItemValue("lgn"));
        	geoMarker = new google.maps.Marker({
                    map: GeofenceMaps,
                    position: geoPos
                });
                GeofenceMaps.setCenter(geoPos);
                
                geocoder.geocode({'latLng': geoPos}, function(results, status) {
                  if (status == google.maps.GeocoderStatus.OK) {
                    if (results[0]) {
                      if (geoMarker != null) geoMarker.setMap(null);
                      geoMarker = new google.maps.Marker({
                          position: geoPos,
                          map: GeofenceMaps
                      });
                      
                      var populationOptions = {
                          strokeColor: '#FF0000',
                          strokeOpacity: 0.8,
                          strokeWeight: 2,
                          fillColor: '#FF0000',
                          fillOpacity: 0.35,
                          map: GeofenceMaps,
                          center: geoPos,
                          radius: 100
                        };
                        cityCircle = new google.maps.Circle(populationOptions);
                      
                      geoInfowindow.setContent('<div id="info_window"><span id="geocodedAddress">' + results[0].formatted_address + '</span><br/><strong>Latitude :</strong> ' + Math.round(vwFrmClnt.getItemValue("lat")*1000000)/1000000 + ' | <strong>Longitude :</strong> ' + Math.round(vwFrmClnt.getItemValue("lgn")*1000000)/1000000 + '<br/>' + bookmark() + '</div>');
                      geoInfowindow.open(GeofenceMaps, geoMarker);
                    }
                  } else {
                      if (geoMarker != null) geoMarker.setMap(null);
                      geoMarker = new google.maps.Marker({
                          position: geoPos,
                          map: GeofenceMaps
                      });
                      
                      var populationOptions = {
                          strokeColor: '#FF0000',
                          strokeOpacity: 0.8,
                          strokeWeight: 2,
                          fillColor: '#FF0000',
                          fillOpacity: 0.35,
                          map: GeofenceMaps,
                          center: geoPos,
                          radius: 100
                        };
                      cityCircle = new google.maps.Circle(populationOptions);  
                        
                      geoInfowindow.setContent('<div id="info_window"><span id="geocodedAddress">' + 'No resolved address' + '</span><br/><strong>Latitude :</strong> ' + Math.round(vwFrmClnt.getItemValue("lat")*1000000)/1000000 + ' | <strong>Longitude :</strong> ' + Math.round(vwFrmClnt.getItemValue("lgn")*1000000)/1000000 + '<br/>' + bookmark() + '</div>');
                      geoInfowindow.open(GeofenceMaps, geoMarker);
                  }
                });
        
                  }, function() {
                    	geoMarker = new google.maps.Marker({
                                map: GeofenceMaps,
                                position: myGeoLatlng
                            });
                            
                            var populationOptions = {
                              strokeColor: '#FF0000',
                              strokeOpacity: 0.8,
                              strokeWeight: 2,
                              fillColor: '#FF0000',
                              fillOpacity: 0.35,
                              map: GeofenceMaps,
                              center: geoPos,
                              radius: 100
                            };
                            cityCircle = new google.maps.Circle(populationOptions);
                            
                    	geoInfowindow.setContent('Geolocation error.');
                    	geoInfowindow.open(GeofenceMaps, geoMarker);
                    
                  });
        }
        else
        {
        }
        
        google.maps.event.addListener(GeofenceMaps, 'click', codeLatLngfromclick);            
                    
        function codeLatLngfromclick(event) {
            var lat = event.latLng.lat();
            var lng = event.latLng.lng();
            var latlng = event.latLng;
            geocoder.geocode({'latLng': latlng}, function(results, status) {
              if (status == google.maps.GeocoderStatus.OK) {
                if (results[0]) {
        	  if (geoMarker != null) geoMarker.setMap(null);
        	  geoMarker = new google.maps.Marker({
                      position: latlng,
                      map: GeofenceMaps
                  });
                  
                  var populationOptions = {
                          strokeColor: '#FF0000',
                          strokeOpacity: 0.8,
                          strokeWeight: 2,
                          fillColor: '#FF0000',
                          fillOpacity: 0.35,
                          map: GeofenceMaps,
                          center: latlng,
                          radius: 100
                        };
                  cityCircle = new google.maps.Circle(populationOptions);
                  
                  GeofenceMaps.setCenter(latlng);
        	      geoInfowindow.setContent('<div id="info_window">' + results[0].formatted_address + '<br/><strong>Latitude :</strong> ' + Math.round(lat*1000000)/1000000 + ' | <strong>Longitude :</strong> ' + Math.round(lng*1000000)/1000000 + '<br/>' + bookmark() + '</div>');
                  geoInfowindow.open(GeofenceMaps, geoMarker);
        	   vwFrmClnt.setItemValue("lat", lat );
               vwFrmClnt.setItemValue("lgn", lng );
                }
              } else {
        	  if (geoMarker != null) geoMarker.setMap(null);
        	  geoMarker = new google.maps.Marker({
                      position: latlng,
                      map: GeofenceMaps
                  });
                  
                  var populationOptions = {
                          strokeColor: '#FF0000',
                          strokeOpacity: 0.8,
                          strokeWeight: 2,
                          fillColor: '#FF0000',
                          fillOpacity: 0.35,
                          map: GeofenceMaps,
                          center: latlng,
                          radius: 100
                        };
                  cityCircle = new google.maps.Circle(populationOptions);
                              
                  GeofenceMaps.setCenter(latlng);
        	      geoInfowindow.setContent('<div id="info_window">' + 'No resolved address' + '<br/><strong>Latitude :</strong> ' + Math.round(lat*1000000)/1000000 + ' | <strong>Longitude :</strong> ' + Math.round(lng*1000000)/1000000 + '<br/>' + bookmark() + '</div>');
                  geoInfowindow.open(GeofenceMaps, geoMarker);
        	   vwFrmClnt.setItemValue("lat", lat );
               vwFrmClnt.setItemValue("lgn", lng );
            alert("Geocoder failed due to: " + status);
        	
              }
            });
         }
         
         function bookmark() {
            return "";
         }
         
         function simulateClick(latitude, longitude) {
            var mev = {
                stop: null,
                latLng: new google.maps.LatLng(latitude, longitude)
            }
            google.maps.event.trigger(GeofenceMaps, 'click', mev);
         }
    }[/code]


I checked the code and it looks fine, there is no any visible problems here.

Such problem as in your case can occurs if you are initializing two dataprocessor instances with the same form. ( not the case for the above posted code )

As possible workaround, try to add the next line before calling form.save

vwFrmClnt.resetDataProcessor("updated"); //this one vwFrmClnt.save()