PDA

View Full Version : Problem ---Can not save edited data into database



ca_phoebe
22 Jan 2009, 7:32 AM
Hi, there:

I am a new learner of Extjs. Right now there is a problem blocking me.

I implemented some functions such as loading data page by page, refresh function...what I am working on is to make 'save' function work on the editorGrid panel....my backend is php..it seems like the php gets no query .....and in Ext.Ajax.request(), I do not know how to get the values such as id, attrname and score (in my case)?

Please help me...
Thanks in advance...


this is part of my js code:




var url = './php/iequery.php';
var fields = [
{name:'h_id', mapping:'id'},
{name: 'h_name',mapping:'attrname'},
{name: 'h_score',mapping:'score'}
];
var store = new Ext.data.Store
({
proxy:new Ext.data.HttpProxy({url:url,method:'POST'}),
baseParams:{task:"selectattr"},
reader: new Ext.data.JsonReader({
totalProperty:"total",root:"results",fields:fields})
});


store.load({params:{start:0,limit:15}});
var paging = new Ext.PagingToolbar({
displayInfo:true,
emptyMsg:"No records to display",
displayMsg:"displaying attributes {0}-{1} of {2}",
store:store,
pageSize:15,
items:
[{

enableToggle: true,
text: 'Refresh',
cls: 'x-btn-text-icon details',
toggleHandler: function(btn, pressed)
{
Ext.getCmp("AttrGridPanel").store.reload();
}
},{
enableToggle: true,
text: 'Save',
cls: 'x-btn-text-icon details',
toggleHandler: function(btn, pressed)
{

///save data to table -- scoredAttributes in database
// function(grid, records){

// var id = records.get('h_id');
//var attrname = records.get('h_name');
//var score = records.get('h_score');
Ext.Ajax.request(
{
waitMsg: 'Saving scores in this page now...'
,url: url
,method:'POST'
,params: {
task: "saveattrscore"
,id:id
,attrname:attrname
,score:score

} //end params

,failure:function(response,options){
Ext.MessageBox.alert('Warning','Saving is failed. Please try again.');
} //end failure block
,success:function(response,options){
Ext.MessageBox.alert('Congrats! Your changes have been saved.');


} //end success block

}) //end request

} // end of toggle handler


}]
});

var gridphp = new Ext.grid.EditorGridPanel({
id:"AttrGridPanel",
el:'south', // the div id in .html file
store:store,
cm: cm,
title: 'List of all attributes',
autoHeight: true,
frame: true,
border:true,
//viewConfig:{forceFit: true},
tbar: paging,
clicksToEdit:1 // single-click


});
gridphp.render()
/*



this is my php function:


function saveattrscore(){

$field = 'score';
// $row = $_POST['id'];
$value = $_POST['attrname'];

$attrid = $_POST['id'];
$dblink = connectDB();


$result = queryResult($dblink, $SQL);

while($rec = mysql_fetch_array($result))
$id[] = $rec[$attrid];

// save data to database
if($field == 'score')
{

// this is a test sql to see if it gets into here
$SQL = 'insert into attrscore values (8,null,8,8)';

$result = queryResult($dblink, $SQL);
}


echo "{success:true, h_id:5,h_score:'.$value.', id: '.$row.',score: '.$field.'}";


mysql_close($dblink);
}

mask_hot
22 Jan 2009, 7:37 AM
Have a look to Saki's RecordForm Extension example.

mjlecomte
22 Jan 2009, 8:03 AM
I'd check the wiki, I think there are some php examples in it. There's also a book out now "Learning ExtJS" that has php examples in it.