Welcome Guest, Not a member yet? Register   Sign In
editing database
#1

[eluser]maniac[/eluser]
Lots of problems learning this, but is fun, especially when I get it to work Smile

Need to edit my database, but keeps looking for a file that isn't in existence, causing an error.

My code, maybe someone can see what I have done wrong (after 2 hours I can't!!) -

Controller -
function editemployee()
{
$data['title']="Edit An Employee";
$data['heading']="Employee Skills Database";
$data['pageheading']="Edit An Employee In The Database";

$this->db->where('empid', $this->uri->segment(3));
$data['query']=$this->db->get('employee');
$this->load->view('editemployeeview', $data);
}

function updateemployee()
{
$data=$_POST;
$this->skillsmodel->updateemployee($data);
header("Location: http://localhost/aStage2CI/index.php/skills/employee");

}

Model -
function updateemployee($data)
{
$this->empid=$data['empid'];
$this->empfirstname=$data['empfirstname'];
$this->emplastname=$data['emplastname'];
$this->deptid=$data['deptid'];

$this->db->update('employee', $this, array('empid'=>$data['empid']));
}

View -
<div id = "content">
<h1 align="center">&lt;?=$pageheading?&gt;</h1>
<br />
&lt;?=form_open('employee/updateemployee');?&gt;
&lt;?=form_hidden('empid',$this->uri->segment(3));?&gt;

<p>Employee First Name: <br />
&lt;input type="text" name="empfirstname"&gt;&lt;/p><br />
<p>Employee Last Name: <br />
&lt;input type="text" name="emplastname"&gt;&lt;/p><br />
<p>Department:<br />
&lt;input type="text" name="deptid"&gt;&lt;/p><br />
<p>&lt;input type="submit" name="submit" value="submit"&gt;&lt;/p>
&lt;/form&gt;
</div>

Thanks
#2

[eluser]Bart v B[/eluser]
You mean you can't populate youre database views into youre form?
hmm.. see more things what i should do diffrent.. Wink

Code:
&lt;?php
    
    
    function updateemployee()
    {
      // first load the Model
      $this->load->model->('skillsmodel');
      // then we can use a method..
      $this->skillsmodel->updateemployee();
      // everything ok redirect
      redirect('index.php/skils/employee');
     // header(“Location: http://localhost/aStage2CI/index.php/skills/employee”);
    }

?&gt;
// model
&lt;?php

  function updateemployee()
  {
    // first create a data array()
    $data = array(
                  'empfirstname' => $this->input->post('empfirstname'),
                  'emplastname'  => $this->input->post('emplastname')
                 );
    // do the update on the table, with the data array()
    $this->db->update('employee', $data);
    // where he must update
    $this->db->where($this->input->post('empid'));
  }

<div id = “content”>
      <h1 align=“center”>&lt;?php echo $pageheading; ?&gt;</h1>
      

      &lt;?php echo form_open('employee/updateemployee');?&gt;
      &lt;?php echo form_hidden('empid',$this->uri->segment(3));?&gt;

        Employee First Name:
        &lt;?php foreach($query as $row)
              {
        ?&gt;
        &lt;input type="text" name="empfirstname" value="&lt;?php echo $row-&gt;empfirstname;?&gt;" /></p>

        Employee Last Name:

        &lt;input type="text" name="emplastname" value="&lt;?php echo $row-&gt;emplastname;?&gt;" /></p>

        Department:

        &lt;input type="text" name="deptid" value="&lt;?php echo $row-&gt;emtid;?&gt;" /></p>
        &lt;?php
          }
          ?&gt;

        &lt;input type=“submit” name=“submit” value=“submit”&gt;&lt;/p>
      &lt;/form&gt;
  </div>

Whoops i made a little mistake i think, but it should be something like this.




Theme © iAndrew 2016 - Forum software by © MyBB