Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Ray on Sep 18, 2009 14:20
open dhtmlx forum
update like a sample

Hi,
i'm not able to understand why this code not update row:

MY INDEX PAGE:

<!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" dir="ltr" lang="en-US">
<head>
    <title>D.B. Group Punch Management</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="STYLESHEET" type="text/css" href="includes/dhtmlxSuite/dhtmlxGrid/codebase/dhtmlxgrid.css">
    <link rel="STYLESHEET" type="text/css" href="includes/dhtmlxSuite/dhtmlxGrid/codebase/dhtmlxgrid_skins.css">
<script src="includes/dhtmlxSuite/dhtmlxGrid/codebase/dhtmlxcommon.js"></script>
    <script src="includes/dhtmlxSuite/dhtmlxGrid/codebase/dhtmlxgrid.js"></script>        
    <script src="includes/dhtmlxSuite/dhtmlxGrid/codebase/dhtmlxgridcell.js"></script>
    <script src="includes/dhtmlxSuite/dhtmlxGrid/codebase/excells/dhtmlxgrid_excell_link.js"></script>
    <script src="includes/dhtmlxSuite/dhtmlxGrid/codebase/ext/dhtmlxgrid_filter.js"></script>
    <script src="includes/dhtmlxSuite/dhtmlxDataProcessor/codebase/dhtmlxdataprocessor.js"></script>
    <script src="includes/dhtmlxSuite/dhtmlxDataProcessor/codebase/dhtmlxdataprocessor_debug.js"></script>
    <script src="includes/dhtmlxSuite/dhtmlxConnector/codebase/connector.js"></script>
    
</head>

<body>

<div id="timesheet" style="width:757px;height:250px;"></div>
<br>
<input type="button" name="update" value="Aggiorna Dati" onclick="myDataProcessor.sendData();">
</div>
<script>
var mygrid;
mygrid = new dhtmlXGridObject('timesheet');
mygrid.setImagePath("includes/dhtmlxSuite/dhtmlxGrid/codebase/imgs/");
mygrid.setHeader("id,emp,Orario Ingresso,Nota Ingresso,Orario Uscita,Nota Uscita,Stato");
mygrid.attachHeader("#select_filter,#select_filter,#select_filter,#select_filter,#select_filter,#select_filter,#rspan");
mygrid.setInitWidths("30,30,133,150,150,150,160");
mygrid.setColAlign("left,left,left,left,center");
mygrid.setSkin("modern");
mygrid.setColSorting("str,str,str,str,str,str");
mygrid.setColTypes("ro,ro,ed,ed,ed,ed,ch");
mygrid.init();
mygrid.loadXML("includes/php/getdata3.php");    //Data Processor



//============================================================================================
myDataProcessor = new dataProcessor("includes/php/update3.php"); //lock feed url
myDataProcessor.enableDebug(true);
myDataProcessor.init(mygrid); //link dataprocessor to the grid
//============================================================================================
</script>
</div>

</body>
</html>

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 '<rows id="0">';
//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("<cell><![CDATA[".$row['attendance_id']."]]></cell>");
        print("<cell><![CDATA[".$row['employee_id']."]]></cell>");
        print("<cell><![CDATA[".$row['punchin_time']."]]></cell>");
        print("<cell><![CDATA[".$row['in_note']."]]></cell>");
        print("<cell><![CDATA[".$row['punchout_time']."]]></cell>");
        print("<cell><![CDATA[".$row['out_note']."]]></cell>");
        print("<cell><![CDATA[".$row['status']."]]></cell>");
        print("</row>");
    }
}else{
//error occurs
    echo mysql_errno().": ".mysql_error()." at ".__LINE__." line in ".__FILE__." file<br>";
}
echo '</rows>';



?>

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 "<data>";
echo "<action type='".$action."' sid='".$rowId."' tid='".$newId."'/>";
echo "</data>";

?>

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"?><data><action type='update' sid='' tid=''/></data>

Incorrect SID, row with such ID not exists in grid
Action: update SID: TID:
row unmarked [updated,valid]

what is wrong?
Thank U
Answer posted by dhxSupport on Sep 23, 2009 03:39
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 http://dhtmlx.com/docs/products/dhtmlxConnector/index.shtml
http://dhtmlx.com/dhxdocs/doku.php?id=dhtmlxconnector:toc