Update like a sample

Hi,

i’m not able to understand why this code not update row:



MY INDEX PAGE:









    D.B. Group Punch Management

    

    

    



            

    

    

    

    

    

    

    






























MY GETDATA CODE:



<?php
//include db connection settings
//change this setting according to your environment
require_once("config.php");
//include XML Header (as response will be in xml format)
header("Content-type: text/xml");
//encoding may be different in your case
echo('<?xml version="1.0" encoding="iso-8859-1"?>‘);

//start output of data

echo ‘’;

//output data from DB as XML

$sql = “SELECT * FROM hs_hr_attendance”;







$res = mysql_query ($sql);



if($res){

    while($row=mysql_fetch_array($res)){

        //create xml tag for grid’s row

        echo ("<row id=’“.$row[‘attendance_id’].”‘>“);

        print(”“);

        print(”“);

        print(”“);

        print(”“);

        print(”“);

        print(”“);

        print(”“);

        print(”“);

    }

}else{

//error occurs

    echo mysql_errno().”: “.mysql_error().” at “.LINE.” line in “.FILE.” file
";

}

echo ‘’;







?>



MY UPDATE CODE:



<?php
//code below is simplified - in real app you will want to have some kins session based autorization and input value checking

//include db connection settings
require_once("config.php");



function update_row(){
    $sql =     "UPDATE hs_hr_attendance SET " .
                "attendance_id=    '".$_GET["c0"]."',
                employee_id=    '".$_GET["c1"]."',
                punchin_time='".$_GET["c2"]."',
                punchout_time=        '".$_GET["c3"]."',
                in_note=        '".$_GET["c4"]."',
                out_note=        '".$_GET["c5"]."',
                status=    '".$_GET["c6"]."',
            WHERE attendance_id=".$_GET["c0"];
    $res = mysql_query($sql);
    
    return "update";    
}

//include XML Header (as response will be in xml format)
header("Content-type: text/xml");
//encoding may differ in your case
echo('<?xml version="1.0" encoding="iso-8859-1"?>’);





$mode = $_GET[“!nativeeditor_status”]; //get request mode

$rowId = $GET[“gr_id”]; //id or row which was updated

$newId = $GET[“gr_id”]; //will be used for insert operation





switch($mode){

    case “inserted”:

        //row adding request

        $action = add_row();

    break;

    case “deleted”:

        //row deleting request

        $action = delete_row();

    break;

    default:

        //row updating request

        $action = update_row();

    break;

}





//output update results

echo “”;

echo “”;

echo “”;



?>



THE ERROR CODE IS:



Log:

Incorrect SID, row with such ID not exists in grid

Action: update SID: TID:

row unmarked [updated,valid]

row 2 marked [updated,valid]

Initiating data sending for 2

Initiating data sending for all rows

Sending all data at once

Server url: includes/php/update3.php?editing=true parameters



2_gr_id=2

2_c0=2

2_c1=5

2_c2=2009-01-22%2010%3A41%3A20

2_c3=Entrat

2_c4=2009-01-22%2018%3A40%3A21

2_c5=Uscita

2_c6=1

2
!nativeeditor_status=updated

2
!nativeeditor_status=

ids=2



Server response received details



<?xml version="1.0" encoding="iso-8859-1"?>



Incorrect SID, row with such ID not exists in grid

Action: update SID: TID:

row unmarked [updated,valid]



what is wrong?

Thank U

Please check if all rows in your grid have unique id.
Also you can try to use dhtmlxConnectors extension you can help you simplify server side operations. Please find more information here dhtmlx.com/dhxdocs/doku.php?id=d … nector:toc

I’ve got the same problem. In my case “Id” is a primary key, so it is definitively unique. A more comprehensive advise and samples how to handle complex updates (especially for beginners :wink: ) would be very nice.

If you are using dhtmlxConnectors you can enable logging and check if any error occur while you try to load or update grid

$grid->enable_log("temp.log",true);

how to handle complex updates (especially for beginners :wink: ) would be very nice.
Tutorial is available here
docs.dhtmlx.com/doku.php?id=dhtm … ex_updates

Hello,

I’ve got the same problem: “Incorrect SID…”. My ID is unique (timestamp). Besides, I add the row, it is recorded in MySQL, but it does not appear in the grid unless I reload the page.

The problem occurs with this code:


<script>

function new_line(ttt)
{
mygrid.addRow(ttt,[new Date(),"","","","",""],0);
mygrid.clearAndLoad("load_articles.php");
}

</script>		
		
<button value="add row" onclick='var d = new Date(); var timejul = d.getTime(); new_line(timejul);'>Add an article</button>


It seems that the problem only occurs when I use the clearAndLoad() function.

It has to be noted that I have good reasons (I am almost obliged) to use the clearAndLoad() function. Indeed, without it, the addRow() function would be very long and I have numerous problems with ’ and " and [double][triple]slashes to add with php code.

In my opinion:

I call the addrow() function, but is it possible that clearAndLoad applies BEFORE my php connector does its work? In such case, the “load” operation would happen before the php connector page does its work and the error message “Incorrect SID” would be a default error message for this.

My idea was to delay the clearAndLoad() function with adding the following function before it (do not use the javascript timeout() function, it won’t work):


function wait(msecs)
{
  var start = new Date().getTime();
  var cur = start
  while(cur - start < msecs)
  {
    cur = new Date().getTime();
  }
} 

function new_line(ttt)
{
mygrid.addRow(ttt,[new Date(),"","","","",""],0);
wait(1000);
mygrid.clearAndLoad("load_articles.php");
}

It works: the added row always appears in grid (just like without clearAndLoad) and is updated after 1 second. However, the error “Incorrect SID” still occurs, but actually everything goes fine.

I hope this can help. I was testing while writing this message. The problem really seems to be that your php connectors go slower than javascript when you use clearAndLoad() function right after the addrow() function.

For people not using clear(), load() and clearAndLoad() right after the addrow() function, my theory is wrong.

I may thus be totally wrong, but I think there is something to check about what operates first (javascript addrow(), php operations, load() etc.)… The order is not always respected, since with some tests, the problem only occurred sometimes.