• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Database update problem?????????

#1
[eluser]Unknown[/eluser]
Hello All

When i click on edit button to edit the database entry. It doesn't shows me any thing.

My Controller:-

function edit($id=0){
if ($this->input->post('name')){
$this->cat_model->updateCategory();
$this->session->set_flashdata('message','Category updated');
redirect('admin/categories/index','refresh');
}else{
//$id = $this->uri->segment(4);
$data['title'] = "Edit Category";
$data['main'] = 'admin_cat_edit';
$this->load->model('cat_model');
$data['category'] = $this->cat_model->getCategory($id);
//$data['categories'] = $this->cat_model->getAllCategories();
if (!count($data['category'])){
redirect('admin/categories/index','refresh');
}
$this->load->vars($data);
$this->load->view('dashboard');
}
}

My Model

function updateCategory(){
$data = array(
'name' => db_clean($_POST['name']),
'shortdesc' => db_clean($_POST['shortdesc']),
'longdesc' => db_clean($_POST['longdesc'],5000),

);

$this->db->where('id', id_clean($_POST['id']));
$this->db->update('categories', $data);
}


View:

<h1>&lt;?php echo $title;?&gt;</h1>

&lt;?php
echo form_open('admin/categories/edit');
echo "<p><label for='name'>Name</label><br/>";
$data = array('name'=>'name','id'=>'name','size'=>25, 'value' => $category['name']);
echo form_input($data) ."</p>";

echo "<p><label for='shortdesc'>Short Description</label><br/>";
$data = array('name'=>'shortdesc','id'=>'shortdesc','size'=>40, 'value' => $category['shortdesc']);
echo form_input($data) ."</p>";

echo "<p><label for='longdesc'>Long Description</label><br/>";
$data = array('name'=>'longdesc','id'=>'longdesc','rows'=>5, 'cols'=>'40', 'value' => $category['longdesc']);
echo form_textarea($data) ."</p>";


echo form_hidden('id',$category['id']);
echo form_submit('submit','update category');
echo form_close();


My Database Design :-

mysql> describe categories;
+-----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(255) | NO | | NULL | |
| shortdesc | varchar(255) | NO | | NULL | |
| longdesc | text | NO | | NULL | |
+-----------+--------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.