Welcome Guest, Not a member yet? Register   Sign In
NEED HELP - Update Data
#1

[eluser]BobyKurniawan[/eluser]
Hey, i'm quite new in CI and i get very 'excited', but i'm stuck now. I try to update my data from database and i get error. Here is my error

Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined variable: nim

Filename: models/biodat.php

Line Number: 28

and here my codes

Code:
function selb($id)
{
$tmpl['tampilan']=$this->biodat->sel_bio($id);
$this->load->view('formupdate',$tmpl);
}
function updatebi($id)
{
$id = $this->input->GET('id');
$nim = $this->input->POST('nim');
$nama = $this->input->POST('nama');
$jurusan = $this->input->POST('jurusan');
$kelas = $this->input->POST('kelas');
$alamat = $this->input->POST('alamat');
$telp= $this->input->POST('telp');
  $data['nim']=$nim;
  $data['nama']=$nama;
  $data['jurusan']=$jurusan;
  $data['kelas']=$kelas;
  $data['alamat']=$alamat;
  $data['telepon']=$telp;
  $kon['id']=$id;
  $this->biodat->updt($data,$kon);
}

and my model

Code:
function sel_bio($id)
  {
$sel=  $this->db->query('select * from biodata_mhs where id ='.$id);
return $sel->result();
}
function updt($data,$kon)
{
$data = array (
'nim' => $nim,
'nama'=> $nama,
'jurusan'=>$jurusan,
'kelas'=>$kelas,
'alamat'=>$alamat,
'telepon'=>$telepon
);
$ids = $kon['id'];
$this->db->where('id',$ids);
$this->db->update('biodata_mhs',$data);
}

note : Every variables are Undefined. Please help Sad.

Sorry for bad english.
#2

[eluser]kamikaz[/eluser]
Hi,

You are in your model, you cannot access variable like in your view Wink

You don't need to rebuild an associative array in your model, you just did it in your controller.
#3

[eluser]Tim Brownlaw[/eluser]
Yep, just like kamikaz said...

You need to remove this...
Code:
$data = array (
'nim' => $nim,
'nama'=> $nama,
'jurusan'=>$jurusan,
'kelas'=>$kelas,
'alamat'=>$alamat,
'telepon'=>$telepon
);
out of your model as you are passing $data as a parameter in your function call which already has the values.

Also, all of those variables $nim, $nama etc, do not exist in the scope of the function...
They are local to the function and they are not defined! Which is why you are getting the error...

So you've defined the $data array in your controller and passing it to your models method (function), which is all you need to do...

Let us know how that goes for you!

Cheers
Tim
#4

[eluser]BobyKurniawan[/eluser]
First. Great thanks the errors are gone.

Second. The records didn't change

Thenn i delete this line from my controller

Code:
$id = $this->input->GET('id');

Now, everything work great. Thank you.

BTW, hi from indonesia




Theme © iAndrew 2016 - Forum software by © MyBB