[eluser]Unknown[/eluser]
Iam confused to delete images in update data, please help me..
my controller
============
public function update()
{
//product id
$id = $this->uri->segment(4);
//if save button was clicked, get the data sent via post
if ($this->input->server('REQUEST_METHOD') === 'POST')
{
//form validation
$this->form_validation->set_rules('description', 'description', 'required');
$this->form_validation->set_rules('name', 'name', 'required');
$this->form_validation->set_rules('price', 'price', 'required|numeric');
//$this->form_validation->set_rules('picture', 'picture', 'required');
$this->form_validation->set_rules('category_id', 'category_id', 'required');
$this->form_validation->set_error_delimiters('<div class="alert alert-error"><a class="close" data-dismiss="alert">×</a><strong>', '</strong></div>');
//if the form has passed through the validation
if ($this->form_validation->run())
{
$data_to_store = array(
'description' => $this->input->post('description'),
'name' => $this->input->post('name'),
'price' => $this->input->post('price'),
'picture' => $this->input->post('delpicture'),
'category_id' => $this->input->post('category_id')
);
//if the insert has returned true then we show the flash message
if($this->products_model->update_product($id, $data_to_store) == TRUE){
$this->session->set_flashdata('flash_message', 'updated');
}else{
$this->session->set_flashdata('flash_message', 'not_updated');
}
redirect('admin/products/update/'.$id.'');
}//validation run
}
//if we are updating, and the data did not pass trough the validation
//the code below wel reload the current data
//product data
$data['product'] = $this->products_model->get_product_by_id($id);
//fetch manufactures data to populate the select field
$data['categorys'] = $this->category_model->get_category();
//load the view
$data['main_content'] = 'admin/products/edit';
$this->load->view('includes/template', $data);
}
my model
=========
function update_product($id, $data)
{
$this->db->where('id', $id);
$this->db->update('products', $data);
$report = array();
$report['error'] = $this->db->_error_number();
$report['message'] = $this->db->_error_message();
if($report !== 0){
return true;
}else{
return false;
}
}
my view
========
echo form_open('admin/products/update/'.$this->uri->segment(4).'', $attributes);
?>
<fieldset>
<?php
echo '<div class="control-group">';
echo '<label for="category_id" class="control-label">Category</label>';
echo '<div class="controls">';
//echo form_dropdown('manufacture_id', $options_manufacture, '', 'class="span2"');
echo form_dropdown('category_id', $options_category, $product[0]['category_id'], 'class="span2"');
echo '</div>';
echo '</div">';
?>
<br />
<div class="control-group">
<label for="inputError" class="control-label">Name</label>
<div class="controls">
<input type="text" id="" name="name" value="<?php echo $product[0]['name']; ?>">
<!--<span class="help-inline">Cost Price</span>-->
</div>
</div>
<div class="control-group">
<label for="inputError" class="control-label">Description</label>
<div class="controls">
<input type="text" id="" name="description" value="<?php echo $product[0]['description']; ?>" >
<!--<span class="help-inline">Woohoo!</span>-->
</div>
</div>
<div class="control-group">
<label for="inputError" class="control-label">Price</label>
<div class="controls">
<input type="text" id="" name="price" value="<?php echo $product[0]['price'];?>">
<!--<span class="help-inline">Cost Price</span>-->
</div>
</div>
<div class="control-group">
<label for="inputError" class="control-label">Picture</label>
<div class="controls">
<img src="<?php echo base_url().$product[0]['picture']; ?>" />
<!--<span class="help-inline">OOps</span>-->
</div>
</div>
<div class="control-group">
<label for="inputError" class="control-label">Change Picture : </label>
<div class="controls">
<input type="file" name="userfile" size="50" />
<div 0 0 15px;">
<strong>NOTE : </strong> <br />
- Images width :700px <br />
- Images height : 600px <br />
- Type file : Jpg, Png, Gif
</div>
<!--<span class="help-inline">OOps</span>-->
</div>
</div>
<div class="form-actions">
<button class="btn btn-primary" type="submit">Save changes</button>
<button class="btn" type="reset">Cancel</button>
</div>
</fieldset>
<?php echo form_close(); ?>
thank you...