[eluser]Neoraj3.0[/eluser]
Hi I am trying to do a mysql update to the image name (the actually file upload to the folder works fine) but the name does not edit. Here is my code:
Model::
Code:
function update_project($projectID, $data)
{
$this->db->where('projectid', $projectID);
$this->db->update('projects', $data);
}
Controller::
Code:
function editprojectimage($projectID) //edit project page
{
//get project by id number
$data['indiv_project'] = $this->project->single_project($projectID);
$this->load->view('templates/header');
$this->load->view('edit-project-image', $data);
$this->load->view('templates/footer');
}
function editprojectimage_pro($projectID)
{
$config['upload_path'] = './assets/images/projectImages';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '2000';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
//check for errors with the upload
$error = array('error' => $this->upload->display_errors());
$this->load->view('templates/header');
$this->load->view('edit-project-image');
$this->load->view('templates/footer');
}
else
{
//upload the new image
$upload_data = $this->upload->data();
$image_name = $upload_data['file_name'];
if($_POST){
$data = array(
'image'=>$image_name
);
//update
$this->project->update_project($data);
}
redirect(base_url().'projects/allprojects');
}
}
View::
Code:
<form class="form-horizontal form-register" enctype="multipart/form-data" action="<?=base_url()?>projects/editprojectimage_pro/<?=$indiv_project['projectid']?>" method="post">
<h2 class="form-signin-heading">Edit Project Image</h2>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label lbl-adj" for="textinput">Project Image Cover</label>
<div class="col-md-4">
<!-- displays the current image in the upload button -->
<button id="btnfile">
<img src="<?=base_url()?>assets/images/projectImages/<?= $indiv_project['image'] ?>" alt="Image" class="media-object img-rounded thumb48" width="42" height="42">
</button>
<input type="file" id="uplodfile" name="userfile" />
</div>
</div>
<button class="btn btn-lg btn-primary" type="submit">Edit Image</button>
</form>