Welcome Guest, Not a member yet? Register   Sign In
HI guys how can i use same form for edit and add data into database?
#6

[eluser]Waqar[/eluser]
Here is my controler

Code:
function add_edit()
    {
        $data['query']= $this->tpc_model->add_individual();
        redirect('individual/index');
    }

model
Code:
function add_individual()
    {
    
        $data = array(
        'title'=>$this->input->post('title'),
        'firstname' =>$this->input->post('firstname'),
        'surname' =>$this->input->post('surname'),
        'initials' =>$this->input->post('initial'),);
              
               if($id = $this->input->post('id'))
        {
            $where = "id = '$id'";
            $query = $this->db->update('individuals', $data, $where);
        }
        else
        {
            $query = $this->db->insert('individuals', $data);
        }
my view
Code:
$attributes = array('class' => 'indvidual', 'id' => 'individualform');
echo form_open('individual/add',$attributes);?>

<?php form_hidden('id',$id);?>
        <label for="title">Title: </label>
        &lt;?php $options = array(
                  'Mr'  => 'Mr',
                  'Mrs'    => 'Mrs',
                  'Ms'   => 'Ms',
                  'Dr' => 'Dr',
              'Prof' => 'Prof',
                );
                
        echo form_dropdown('title', $options);?&gt;<br>
    <label for="firstname">First Name: </label>
        &lt;input type="text" id="firstname" name="firstname" value="&lt;?=$firstname; ?&gt;"&gt;&lt;br>
        <label for="surname">Surname: </label>
        &lt;input type="text" id="surname" name="surname"&gt;&lt;br>
        <label for="initial">Initials: </label>
        &lt;input type="text" id="initial" name="initial"&gt;&lt;br>
        &lt;input type="submit" id="go" value="Save"&gt;&nbsp;
        &lt;?= form_close();?&gt;


Messages In This Thread
HI guys how can i use same form for edit and add data into database? - by El Forum - 04-07-2009, 08:26 AM



Theme © iAndrew 2016 - Forum software by © MyBB