0

I am new to codeigniter, I have managed to get insert working into the database and I have done the code to delete from the database however when clicking on the job to delete it, it just refreshes and the job is still in the database.

My Controller

public function deleteclientform(){
    $this->load->helper('form');
    $this->load->model("clientmodel"); 
    $data['clients']=$this->clientmodel->getallclients();
    $data['title']="Delete Job";
    $this->load->view("deleteclientform",$data); 
}

public function delete(){
    $films=$this->input->post('clients');
    $this->load->model("clientmodel");
    foreach($clients as $jobno)
    {
        $this->clientmodel->deleteclient($jobno);
    }
     redirect('/nav/home', 'refresh');
}

My Model

function deleteclient($jobno)

{
$this->db->where('jobno', $jobno);
$result=$this->db->delete('client');
return $result;
}

My View

echo form_open('client/delete');

foreach($clients as $client)
{
echo "<p>";
echo form_label($client->job, 'client'.$client->jobno);
$data = array('name' => 'clients[]', 'jobno'=>'client'.$client->jobno, 'value' =>    $client->jobno);
echo form_checkbox($data);
echo "</p>";
}
echo form_submit("delete_btn","Delete these Jobs");
echo form_close();
2
  • Where does $clients come from in your controller? clients/delete? Commented May 8, 2014 at 13:51
  • This, foreach($clients as $jobno) should be foreach($films as $jobno) Commented May 8, 2014 at 13:51

1 Answer 1

1
public function delete(){
    $films=$this->input->post('clients');
    $this->load->model("clientmodel");
    foreach($films as $jobno)
              ^ this
    {
        $this->clientmodel->deleteclient($jobno);
    }
     redirect('/nav/home', 'refresh');
}

This function in your controller was wrong.

You were referring to $clients when it was $films you wanted.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.