0

Why is it not deleting? When I press delete, I should get the id of the row that I will delete.

View:

<?php
foreach ($cust_data as $row) {
    echo '<tr class="even pointer">';
    echo '<td class="a-center ">';
    echo '<input type="checkbox" class="tableflat">';
    echo '</td>';
    echo'<td>' . $row->cust_id . '</td>';
    echo'<td>' . $row->firstname . '</td>';
    echo'<td>' . $row->lastname . '</td>';
    echo'<td>' . $row->email . '</td>';
    echo'<td>' . $row->contact_number . '</td>';
    echo'<td>' . $row->address . '</td>';
    echo'<td>';
    echo '<a href="' . base_url() . 'administrator/delete?id=' . $row->cust_id . '">Delete</a>';
    echo'</td>';
    echo'</tr>';
}
?>    

Model:

public function delete($id) {
    $this->db->delete('customer', array('cust_id' => $id));
}

Controller:

public function delete() {
    $this->load->model('admin_model');
    $this->admin_model->delete($this->input->get('cust_id'));
    $this->customer();
}
1
  • $this->input->get('cust_id') should be $this->input->get('id') that's why it doesn't get the value because you are retrieving a wrong/unsetted posted data Commented Mar 15, 2016 at 1:10

1 Answer 1

1

I have noticed that you used to post the value of id in your code:

echo '<a href="' . base_url() . 'administrator/delete?id=' . $row->cust_id . '">Delete</a>';

while on your controller you used the get() using the name of cust_id:

$this->admin_model->delete($this->input->get('cust_id'));

you cannot get any value because cust_id is not the name of the posted value. so change your cust_id to id like the example below:

public function delete() {
    $this->load->model('admin_model');
    $this->admin_model->delete($this->input->get('id'));
    $this->customer();
}
Sign up to request clarification or add additional context in comments.

4 Comments

@leo balino thanks dude i tried to solve it for almost hour. :) but i would ask a stupid question again so it will be cleared in my mind coz im still practicing CI where that get('id') come from? im just confused sorry :)
@EdgarOng lad it came from your view you declared it on echo '<a href="' . base_url() . 'administrator/delete?id=' . $row->cust_id . '">Delete</a>'; administrator/delete?id=
@EdgarOng when you click the link the address bar shows localhost/administrator/delete?id=123 am I right? so the posted data is 123 to get it either $_GET('id'); or the $this->input->get('id');
@leobalino thank you so much it helped me a lot. have a good day! :)

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.