This is a migrated thread and some comments may be shown as answers.

Can't update data after creating data

0 Answers 78 Views
Grid
This is a migrated thread and some comments may be shown as answers.
rooney
Top achievements
Rank 1
rooney asked on 15 Oct 2012, 03:14 AM
Hi all, i have some problem with create and update data
Look at this

dataSource = new kendo.data.DataSource({
   transport: {
      read: {url:"<?=base_url()?>/bank"},
      update: {url:"<?=base_url()?>/bank/update", type:"POST"},
      destroy: {url:"<?=base_url()?>/bank/destroy",type:"POST"},
      create: {url:"<?=base_url()?>/bank/create",type:"POST"},
   },
   error: function(e) {
      alert(e.responseText);
   },
   batch: true, pageSize: 25,
   schema: {
   model: {
      id: "id_bank",
      fields: {
         nama_bank: { type: "string" },
      }
   }
}
});
//kendo grid
$("#grid_bank").kendoGrid({
   dataSource: dataSource,
   editable:  "popup", height: 450, filterable: true, sortable: true, pageable: true,
   toolbar: ["create"],
   columns: [
      { field: "nama_bank",title: "Nama", filterable: true },
      { command: ["edit", "destroy"], title: " ", width: "160px" }
   ]
});

i'am using codeigniter and this script on class controller
public function index() {
   header("Content-type: application/json");
   $arr = array();
   $data=$this->bank_model->get_bank();
   foreach ($data as $hasil) {
      $arr[]=$hasil;
   }   
   print json_encode($arr);
}
     
public function create() {
   header("Content-type: application/json");
   $nama_bank = $_POST['models'][0]['nama_bank'];
   $query = "INSERT INTO bank VALUES (NULL, '$nama_bank')";
   $rs = $this->db->query($query);
   echo $query;
   if ($rs) {
      echo json_encode($rs);
   } else {
      header("HTTP/1.1 500 Internal Server Error");
   }
}
     
public function update() {
   header("Content-type: application/json");
   $id_bank = $_POST['models'][0]['id_bank'];
   $nama_bank = $_POST['models'][0]['nama_bank'];
   $query = "UPDATE bank SET nama_bank = '$nama_bank' WHERE id_bank = $id_bank";
   echo $query;
   if ($rs) {
      echo json_encode($rs);
   } else {
      header("HTTP/1.1 500 Internal Server Error");
   }
}

the problem is if process creating data is execute after that when will updating data, process always to creating data
and if in first time/page reloaded process updating is execute, that is working, but after that creating data it is problem again

Thank

No answers yet. Maybe you can help?

Tags
Grid
Asked by
rooney
Top achievements
Rank 1
Share this question
or