PDA

View Full Version : Work in 4.0 but not update (db) in 4.1



surjikoff
1 Jul 2012, 5:53 AM
function showSeasonWin(){
Ext.onReady(function(){
Ext.define('SeasonModel', {
extend: 'Ext.data.Model',
fields: [ ]
});


var seasonstore = Ext.create('Ext.data.Store', {
autoLoad: false,
autoSync: false,
model: 'SeasonModel',
storeId: 'SeasonStoreID',
proxy: {
type: 'ajax',
url: 'config/db-vypiski.php',
actionMethods: {
create : 'POST',
read : 'GET',
update : 'POST',
destroy: 'POST',
},
reader: {
type: 'json',
root: '',
},
writer: {
type: 'json',
root: '',
}
}
});


Ext.grid.RowEditor.prototype.saveBtnText = 'Обновить'; Ext.grid.RowEditor.prototype.cancelBtnText = 'Отмена';

var RowEdit = Ext.create('Ext.grid.plugin.RowEditing', {
clicksToEdit: 2,
autoCancel: false,
listeners: {
beforeedit: function() {
Ext.TaskManager.stop(task_start);
},
cancelEdit: function() {
Ext.TaskManager.start(task_start);
}
}
});

RowEdit.on({
scope: this,
afteredit: function(add) {
Ext.TaskManager.start(task_start);
Ext.Ajax.request({
url : 'config/db-vypiski.php',
waitMsg: 'Пожалуйста подождите...',
method: 'POST',
params: {task_update:'add',
f1: add.record.data.step_id,
f2: add.record.data.real_timedate,
f3: add.record.data.prep_timedate,
f4: add.record.data.date_from,
f5: add.record.data.content,
f6: add.record.data.number_zakaz,
f7: add.record.data.summa_oplaty,
f8: add.record.data.summa_zakaza,
f9: add.record.data.manager,
f10: add.record.data.comments
},
success: function() {
seasonstore.load();

}
});
},
});
PHP code

<?php$db = "vypiski";
$table = "_vypiski";
$fr = "step_id";


$link = mysql_connect("localhost", "root","") or die("Could not connect");
mysql_select_db($db) or die("Could not select database");




$task_create = $_POST['task_create'];
$task_delete = $_POST['task_delete'];
$task_update = $_POST['task_update'];
$f1 = $_POST['f1'];
$f2 = $_POST['f2'];
$f3 = $_POST['f3'];
$f4 = $_POST['f4'];
$f5 = $_POST['f5'];
$f6 = $_POST['f6'];
$f7 = $_POST['f7'];
$f8 = $_POST['f8'];
$f9 = $_POST['f9'];
$f10 = $_POST['f10'];
$idx = $_POST['idx'];


switch ($_SERVER["REQUEST_METHOD"])
{
case 'GET':

$fields = array();
$arr = array();

$fields_query = mysql_query("describe $table");
while($fobj = mysql_fetch_object($fields_query)) {
$fobj->name = $fobj->Field;
$fobj->header = $fobj->Field;
$fobj->dataIndex = $fobj->Field;
$fields[] = $fobj;
}
$rs = mysql_query("select * from $table");
while($obj = mysql_fetch_object($rs)) {
$arr[] = $obj;
}
echo '{ metaData: { "root": "data", "fields" : ' . json_encode($fields) . '},"success":true, "data":' . json_encode($arr) . '}';
break;

case 'POST':
if($task_update=='add'){
$a = "UPDATE $table set step_id = '$f1',real_timedate = '$f2',prep_timedate = '$f3',date_from = '$f4',content = '$f5',number_zakaz = '$f6',summa_oplaty = '$f7',summa_zakaza = '$f8',manager = '$f9',comments = '$f10' where step_id ='$f1'";

if (mysql_query($a)) {
echo "{success:true}";
}
else echo "{success:false}";
}

if($task_create=='add'){
$mass = array();
$rss = mysql_query("select $fr from $table");
while ($obj = mysql_fetch_row($rss)) {
$mass[] = $obj;
}
$i = array_pop($mass);
$i = $i[0] + 1;
// echo $i;
$a = "insert into $table value('$i',' ',' ','2010-10-10','Заказ','Номер Заказа','Сумма','Сумма','Выберите Менеджера','Записка')";
if (mysql_query($a)) {
echo "{success:true}";
}
else echo "{success:false}";
}


if($task_delete=='del'){
$a = "DELETE FROM $table WHERE $fr = '$idx' LIMIT 1";
if (mysql_query($a)) {
echo "{success:true}";
}
else echo "{success1:false}";
echo $f1;
}


break;
default:
break;
}
mysql_close();
?>

in 4.0 all work fine. But in 4.1 not work update.

skirtle
1 Jul 2012, 7:40 AM
What do you mean by 'not work'? What actually happens?

My guess would be that the update request is being made but the parameters are all missing. Try adding your fields in your model.

Ideally something like this should probably be done by saving through the model's proxy and writer.

surjikoff
1 Jul 2012, 9:22 AM
Not post in db

scottmartin
1 Jul 2012, 12:33 PM
Have you verified that parameters in your header are send in the same manner as you are looking for in your server?

Example: sort is not send as an object. If your server is not seeing header params correctly, you will get syntax errors in your SQL call. Are there any errors in your response?

Scott.

surjikoff
1 Jul 2012, 1:49 PM
There nothing error. I make grid record, delete grid record. But if i need change data in grid record, i have nothing. Data sent but not post in db. In extjs 4.0 it's work properly.


task_greate add - yes (add new record in grid)
task_delete del - yes (delete record)
task_update ??? nothing This send data to json but not in db.

For example i change data - 2012-07-02

36691
But not have changes

scottmartin
1 Jul 2012, 2:30 PM
You id is null? You may have to dig around a little, or provide more info.

Scott.

surjikoff
2 Jul 2012, 11:10 AM
May be this is RowEdit error?

scottmartin
2 Jul 2012, 12:12 PM
I would start by omitting all of your edit events and work back. I would then verify your server is receiving/sending as expected. This should be a basic operation.

Scott.

surjikoff
2 Jul 2012, 1:16 PM
There all - 36732
in config change $table = "_vypiski"; to $table = "spr_season"