• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Image not update(in database image update blank value)

#1
[eluser]Rocky Mehta[/eluser]
Model page:
Code:
function update_chair($filename)
{
$this->load->database();
$data = array(
   'chair_type' => $this->input->post('chair_type'),
   'chair_image' => $filename
  );
$this->db->where('chair_id', $this->input->post('chair_id'));
$this->db->update('venue_chair',$data);
}
function general()
{
  $data['mchair_id']['value'] = 0;
  $data['chair_type'] = array('name'=>'chair_type','style'=>'width:300px');
  $data['chair_image'] = array('name'=>'chair_image');
  
return $data;
}
view page:
Code:
<tr valign='top'>
   <td>Chair Image</td>
   <td colspan="2">
    &lt;?php echo form_upload('userfile',$chair_image['value']);?&gt;
    &lt;?php
if((int)$mchair_id>0)
{
          echo "<a href='../../../images/".$chair_image[' target='_blank'>View Image</a>";
}
?&gt;
    </td>
</tr>
controller page:
Code:
function main($chair_id = 0)
{
$this->load->model('venue_chair_model');
$data = $this->venue_chair_model->general();
if ($this->input->post('save'))
{
  if ($this->input->post('chair_id'))
  {
   $this->venue_chair_model->do_upload();
   $this->venue_chair_model->update_chair($_FILES['userfile']['name']);
   echo "Data Updated Successfully";
     redirect('http://localhost/venue/index.php/venue_chair/update/');
  }
  else
  {
   $this->venue_chair_model->do_upload();
   $this->venue_chair_model->insert_chair($_FILES['userfile']['name']);
   echo "Data Inserted Successfully";
  }
}
if((int)$chair_id>0)
{
  $query = $this->venue_chair_model->get($chair_id);
  $data['mchair_id']['value']=$query['chair_id'];
  $data['chair_type']['value'] = $query['chair_type'];
  $data['chair_image']['value']=$query['chair_image'];
}
$this->load->view('venue_chair_view',$data);
}
  
function update($chair_id = 0)
{
$this->load->model('venue_chair_model');
$data = $this->venue_chair_model->general();
$data['query'] = $this->venue_chair_model->getall();  
$this->load->view('venue_chair_update',$data);
}
At the update time if no changes in image field(chair_image field) value blank update blank in database.
please gave me solution how can i update a old value which i m fetched from database(if i am not changes that field).

#2
[eluser]louisl[/eluser]
Try getting the filename from upload->data()

Code:
if (!$this->upload->do_upload('userfile') ) {
    
//print_r($this->upload->display_errors());

} else {
    
$upload_data = $this->upload->data();
    
$this->venue_chair_model->update_chair($upload_data['file_name']);
  
}

#3
[eluser]Rocky Mehta[/eluser]
Your code getting me to display my error but not update my field if i am not change the chair_image field update a blank in to database.
if i am change the field(chair_image) it's working properly but if i m not change that field(chair_image) it's update a blank entry in to my database.
my error display is => You did not select a file to upload.

#4
[eluser]Rocky Mehta[/eluser]
yes yes yes i got it i take a variable and set the value then in view page i take form_hidden and pass the hidden field value and my image update is successfully saved.
thank x for help me sir.
controller page:
Code:
$data['mchair_id']['value']=$query['chair_id'];
$data['chair_type']['value'] = $query['chair_type'];
$data['chair_image']['value']= $query['chair_image'];
$data['imagehidden']['value'] = $query['chair_image'];
view page:
Code:
<td colspan="2">
&lt;?php echo form_upload('userfile',$chair_image['value']);
       echo form_hidden('prev_image_name',$imagehidden['value']);
?&gt;
thank x once again CodeIgniter


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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