CodeIgniter Forums

Full Version: How to update data into database using specified id (code ignitor)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Maideen[/eluser]
I am new to codeingiter. I am using code ingniter 2.0.0
Please help me.
Please help me where i did mistake.
I have done model,controller, view. But once update , system store zero into all field in table. Add, View are working well. I also attached the files.

Here is my code
//------------------
here is controller
//-----------------
function editdetails(){
$id = $this->input->post('id');
$data = array(
'code' => $this->input->post('$code'),
'name' => $this->input->post('$name'),
'address' => $this->input->post('$address'),
'tel' => $this->input->post('$tel'),
'fax' => $this->input->post('$fax'),
'email' => $this->input->post('$email'),
'business' => $this->input->post('$business'),
'url' => $this->input->post('$url'),
'rocno' => $this->input->post('$rocno'),);


$this->db->where('id',$id);
$this->db->update('companyinfo', $data);
///load finish view as saved
$this->load->view('msg_disp');
}
///--------------------------
here Model
//--------------------------

function update($id, $data){
$this->db->where('id', $id);
$this->db->update($this->tbl_coinfo, $data);
}

//-----------------
here is view
//-----------------

<?php
echo 'enter into edit page';
echo form_open('company/editdetails');
echo form_hidden('id', $id['value']);


echo form_input($id);
echo form_input($code);
echo form_input($name);
echo form_input($address);
echo form_input($tel);
echo form_input($fax);
echo form_input($email);
echo form_input($business);
echo form_input($url);
echo form_submit('mysubmit', 'Update New');
echo form_close();
?>

Please help me where i did mistake.

El Forum

[eluser]InsiteFX[/eluser]
No will download your zip file!

Your problem is in your Controller editdetails!

And next time please use CODE TAGS!
Code:
// remove ending spaces after code!
[code ]

[/code ]

Now look at my code and see where you made your mistakes!

Controller:
Code:
function editdetails()
{
    $id = $this->input->post('id');

    $data = array(
        'code'     => $this->input->post('code'),
        'name'     => $this->input->post('name'),
        'address'  => $this->input->post('address'),
        'tel'      => $this->input->post('tel'),
        'fax'      => $this->input->post('fax'),
        'email'    => $this->input->post('email'),
        'business' => $this->input->post('business'),
        'url'      => $this->input->post('url'),
        'rocno'    => $this->input->post('rocno')
    );

    $this->db->where('id', $id);
    $this->db->update('companyinfo', $data);

    /// load finish view as saved
    $this->load->view('msg_disp');  
}

Model:
Code:
function update($id, $data)
{
    $this->db->where('id', $id);
    $this->db->update($this->tbl_coinfo, $data);
}

InsiteFX

El Forum

[eluser]Maideen[/eluser]
after changing as your code, Still same problem.
store 0 in the data. pls help me

El Forum

[eluser]InsiteFX[/eluser]
Did you check to see if you are getting any post data back?

Code:
function editdetails()
{
    $id = $this->input->post('id');

    $data = array(
        'code'     => $this->input->post('code'),
        'name'     => $this->input->post('name'),
        'address'  => $this->input->post('address'),
        'tel'      => $this->input->post('tel'),
        'fax'      => $this->input->post('fax'),
        'email'    => $this->input->post('email'),
        'business' => $this->input->post('business'),
        'url'      => $this->input->post('url'),
        'rocno'    => $this->input->post('rocno')
    );

    echo var_dump($data);

    $this->db->where('id', $id);
    $this->db->update('companyinfo', $data);

    /// load finish view as saved
    $this->load->view('msg_disp');  
}
If nothing displays then you are not getting post data!

InsiteFX

El Forum

[eluser]danmontgomery[/eluser]
Code:
echo form_input($id);
echo form_input($code);
echo form_input($name);
echo form_input($address);
echo form_input($tel);
echo form_input($fax);
echo form_input($email);
echo form_input($business);
echo form_input($url);

You need to give your inputs names.

Code:
echo form_input('id', $id);
echo form_input('code', $code);
echo form_input('name', $name);
echo form_input('address', $address);
echo form_input('tel', $tel);
echo form_input('fax', $fax);
echo form_input('email', $email);
echo form_input('business', $business);
echo form_input('url', $url);

This is covered in the user guide.

El Forum

[eluser]Maideen[/eluser]
Hi InsiteFX

first of all Thanks for your WWW Rules. Your are right to understand easily.

Once again thank you . Because i very new to php and codeigniter.

I have added " echo var_dump($data); " as per your suggestion.



I got this result

array(9) { ["code"]=> bool(false) ["name"]=> bool(false) ["address"]=> bool(false) ["tel"]=> bool(false) ["fax"]=> bool(false) ["email"]=> bool(false) ["business"]=> bool(false) ["url"]=> bool(false) ["rocno"]=> bool(false) }

No post back data.

I do not know Where I did wrong?. Please

Once again I give the code

-------Controller

// this is display data from table by id. It works fine. Data are displayed well

function disp_data($id) {
$this->load->model('company_model');
$query = $this->company_model->get_by_id($id);

$data['id']['value'] = $query['id'];
$data['code']['value'] = $query['code'];
$data['name']['value'] = $query['name'];
$data['address']['value'] = $query['address'];
$data['tel']['value'] = $query['tel'];
$data['fax']['value'] = $query['fax'];
$data['email']['value'] = $query['email'];
$data['business']['value'] = $query['business'];
$data['url']['value'] = $query['url'];
$data['rocno']['value'] = $query['rocno'];

$this->load->view('inputco',$data);
}


function update_data(){
$id = $this->input->post('id');
$data = array(
'code' => $this->input->post('code'),
'name' => $this->input->post('name'),
'address' => $this->input->post('address'),
'tel' => $this->input->post('tel'),
'fax' => $this->input->post('fax'),
'email' => $this->input->post('email'),
'business' => $this->input->post('business'),
'url' => $this->input->post('url'),
'rocno' => $this->input->post('rocno'),);

echo var_dump($data); // No post back data.

$this->db->where('id',$id);
//$this->db->where('id',$this->input->post('id')); //i tried this also.
$this->db->update('companyinfo', $data);
//load finish view as saved
$this->load->view('msg_disp');
}

-------- Model (it is also working fine)

function get_by_id($id){
$query = $this->db->get_where('companyinfo', array('id'=>$id));
return $query->row_array();
}

----------View

<?php
echo 'enter into edit page';
echo form_open('company/editdetails');
echo form_hidden('id', $id['value']);
echo form_input($id);
echo form_input($code);
echo form_input($name);
echo form_input($address);
echo form_input($tel);
echo form_input($fax);
echo form_input($email);
echo form_input($business);
echo form_input($url);
echo form_submit('mysubmit', 'Update New');
echo form_close();
?>

El Forum

[eluser]Maideen[/eluser]
I am very new to php and codeigniter.

I have added ” echo var_dump($data); ” as per InsiteFX suggestion.

I got this result

array(9) { [“code”]=> bool(false) [“name”]=> bool(false) [“address”]=> bool(false) [“tel”]=> bool(false) [“fax”]=> bool(false) [“email”]=> bool(false) [“business”]=> bool(false) [“url”]=> bool(false) [“rocno”]=> bool(false) }

No post back data.

I do not know Where I did wrong?. Please help me.

Once again I give the code

———-Controller

// this is display data from table by id. It works fine. Data are displayed well

function disp_data($id) {
$this->load->model(‘company_model’);
$query = $this->company_model->get_by_id($id);

$data[‘id’][‘value’] = $query[‘id’];
$data[‘code’][‘value’] = $query[‘code’];
$data[‘name’][‘value’] = $query[‘name’];
$data[‘address’][‘value’] = $query[‘address’];
$data[‘tel’][‘value’] = $query[‘tel’];
$data[‘fax’][‘value’] = $query[‘fax’];
$data[‘email’][‘value’] = $query[‘email’];
$data[‘business’][‘value’] = $query[‘business’];
$data[‘url’][‘value’] = $query[‘url’];
$data[‘rocno’][‘value’] = $query[‘rocno’];

$this->load->view(‘inputco’,$data);
}


function update_data(){
$id = $this->input->post(‘id’);
$data = array(
‘code’ => $this->input->post(‘code’),
‘name’ => $this->input->post(‘name’),
‘address’ => $this->input->post(‘address’),
‘tel’ => $this->input->post(‘tel’),
‘fax’ => $this->input->post(‘fax’),
‘email’ => $this->input->post(‘email’),
‘business’ => $this->input->post(‘business’),
‘url’ => $this->input->post(‘url’),
‘rocno’ => $this->input->post(‘rocno’),);

echo var_dump($data); // No post back data.

$this->db->where(‘id’,$id);
//$this->db->where(‘id’,$this->input->post(‘id’)); //i tried this also.
$this->db->update(‘companyinfo’, $data);
//load finish view as saved
$this->load->view(‘msg_disp’);
}

————Model (it is also working fine)

function get_by_id($id){
$query = $this->db->get_where(‘companyinfo’, array(‘id’=>$id));
return $query->row_array();
}

—————View

<?php
echo ‘enter into edit page’;
echo form_open(‘company/editdetails’);
echo form_hidden(‘id’, $id[‘value’]);
echo form_input($id);
echo form_input($code);
echo form_input($name);
echo form_input($address);
echo form_input($tel);
echo form_input($fax);
echo form_input($email);
echo form_input($business);
echo form_input($url);
echo form_submit(‘mysubmit’, ‘Update New’);
echo form_close();
?>