CI Update Delete
CI Update Delete
CI Update Delete
<html>
<head><title>form add Category</title>
</head>
<body>
<?php
echo"
<td><a href='".site_url('Category/edit/'.$row->cate_id)."'>Edit</a> |
<a href='".site_url('Category/delete/'.$row-
>cate_id)."'>Delete</a>
</td>
";
}
echo"</tr>";
?>
</table>
</body>
</html>
3. Add function in controller : category.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$this->load->library('upload',$config);
$this->upload->initialize($config);
$uploadData = $this->upload->data();
$picture = $uploadData['file_name'];
if (!$this->upload->do_upload('img1'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('cate_added', $error);
}
else
{
$data=array(
'cate_name'=>$this->input->post('txtname'),
'img'=>$picture,
'dec'=>$this->input->post('txtdec')
);
$this->db->insert('tblcategory',$data);
redirect('Category/index');
}
}
function edit($id){
$row=$this->m->getonerow($id);
$data['r']=$row;
$this->load->view("cate_edit",$data);
function update(){
$id=$this->input->post('id');
$name=$this->input->post('txtname');
$dec=$this->input->post('txtdec');
$config['file_name'] = $_FILES['img1']['name'];
$this->load->library('upload',$config);
$this->upload->initialize($config);
$uploadData = $this->upload->data();
$picture = $uploadData['file_name'];
$data = array(
'cate_name'=>$name,
'img'=>$picture,
'dec'=>$dec
);
$this->db->where('cate_id',$id);
$this->db->update('tblcategory',$data);
redirect("Category/index");
}
function delete($id){
$id=$this->db->where('cate_id',$id);
$this->db->delete('tblcategory');
redirect("Category/index");
}
4. Go to view folder create file’s name cate_edit.php
<html>
<head><title>form add Category</title>
</head>
<body>
<?php
echo"
<td><a href='".site_url('Category/edit/'.$row->cate_id)."'>Edit</a> |
<a href='".site_url('Category/delete/'.$row-
>cate_id)."'>Delete</a>
</td>
";
}
echo"</tr>";
?>
</table>
</body>
</html>