Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by LeitrimMan on Dec 16, 2009 01:17
open dhtmlx forum
dataprocessor fails update, incorrect field name used

hi guys,

I have a grid with a dataprocessor attached as such

userGrid = adminTabBar.cells("adminUsers").attachGrid();
userGrid.setImagePath('codebase/imgs/');
userGrid.setHeader('User Name, Last Login, Access Level, New Password, Blocked');
userGrid.setColTypes("ed,ed,ed,ed,ed");
userGrid.setSkin('light');
userGrid.init();            
                
userDP = new dataProcessor("admindb2.php?action=getUsers&editing=true");
userDP.setVerificator(0, not_empty);
userDP.setUpdateMode("row")
userDP.init(userGrid);        
userGrid.clearAndLoad("admindb2.php?action=getUsers");

On the server side this is..

case "getUsers":
        
$GetUsersSQL = "select UserName, LastAccessed, AccessLevel, '' as NewPass, Blocked from users";
$resconn->enable_log("adminlog.txt");
$resconn->sql->attach("Delete", "Delete from users WHERE UserID={UserID}");
$resconn->event->attach("beforeUpdate","editESIUser");
$resconn->event->attach("beforeInsert","insertUser");
$resconn->render_sql($GetUsersSQL,"UserID","UserName, LastAccessed, AccessLevel, NewPass, Blocked");    
            
        
With two functions

function editESIUser($action)
{
$id = $action->get_id();
$UserName = $action->get_value("UserName");
$UserPass= $action->get_value("NewPass");
                   
$upresult = mysql_query("update users SET UserName='$UserName', UserPass='$UserPass' WHERE UserID=$id");
$action->success();    
}

function insertUser($action)
{
$UserName = $action->get_value("UserName");
$UserPass= $action->get_value("NewPass");
                   
$upresult = mysql_query("insert into users (UserName, UserPass) VALUES ('$UserName', '$UserPass')");
$action->success();    
}

On inserting a new entry into the grid, all works fine. However, whenever I try to update a row, I get a fail and the log entry is

DataProcessor object initialized
1260954385_7_gr_id => 1260954385_7
1260954385_7_c0 => Cyril2
1260954385_7_c1 => 0000-00-00 00:00:00
1260954385_7_c2 => 0
1260954385_7_c3 => Cyril
1260954385_7_c4 => 0
1260954385_7_!nativeeditor_status => updated
ids => 1260954385_7

Row data [1260954385_7]

Incorrect field name used: UserName

data

Incorrect field name used: NewPass

data

Event code for update processed

Edit operation finished
0 => action:updated; sid:1260954385_7; tid:1260954385_7;

Done in 0.00886702537537s

It doesn't seem to recognise the field names in the update mode, although in the insert mode it works fine i.e. heres the log from an update call



DataProcessor object initialized
28000_gr_id => 28000
28000_c0 => Cyril
28000_c1 =>
28000_c2 => 1
28000_c3 => password
28000_c4 =>
28000_!nativeeditor_status => inserted
ids => 28000

Row data [28000]
UserID => 28000
UserName => Cyril
LastAccessed =>
AccessLevel => 1
NewPass => password
Blocked =>
!nativeeditor_status => inserted

INSERT INTO users(UserName,LastAccessed,AccessLevel,NewPass,Blocked) VALUES ('Cyril','','1','password','')

Edit operation finished
0 => action:error; sid:28000; tid:28000;

Done in 0.00695514678955s

How is it possible that the field names are available or passed through on an insert, but not on an update?

thanks!


Answer posted by Alex (support) on Dec 16, 2009 05:43

Hello,

try to modify insertUser function as follows:

function insertUser($action) 

$UserName = $action->get_value("UserName"); 
$UserPass= $action->get_value("NewPass"); 
   
$upresult = mysql_query("insert into users (UserName, UserPass) VALUES ('$UserName', '$UserPass')"); 

$id = mysql_insert_id();

$action->success($id);

}



Answer posted by LeitrimMan on Dec 16, 2009 06:23

Hi, I'm afraid the issue isn't on the insert function which works fine but the function editESIUser($action) funtion -


function editESIUser($action)
{
$id = $action->get_id();
$UserName = $action->get_value("UserName");
$UserPass= $action->get_value("NewPass");
                   
$upresult = mysql_query("update users SET UserName='$UserName', UserPass='$UserPass' WHERE UserID=$id");
$action->success();    
}

Answer posted by Stanislav (support) on Dec 16, 2009 09:52
Do you have some ID field in "users" table?
Currently you have not specified it in your select 
  $GetUsersSQL = "select UserName, LastAccessed, AccessLevel, '' as NewPass, Blocked from users"; 
but have provide as part of constructor
  $resconn->render_sql($GetUsersSQL,"UserID","UserName, LastAccessed, AccessLevel, NewPass, Blocked");  

Because connector can't locate real ID , it generates unique IDs for each record , which fine for data viewing , but such data can't be updated in DB, because pseudo-id , generated by connector, can be linked to the real record in DB

To fix issue you need to include UserID field to the query ( and add such column to the table if it doesn't exists yet ) 

By the way, previous tip, about custom insert operation is actual as well, it doesn't related to update operation, but actual for new record adding scenario. 
Answer posted by LeitrimMan on Dec 16, 2009 11:05

Hi, thats the issue! Thanks for that.. no matter how long I stared I don't think I would have seen that.

 

I will also make the other change i relation to creating the new record.