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();
}
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();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.