Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4329184
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:47:22+00:00 2026-05-21T09:47:22+00:00

I am a bit confused as to the best way to attach this issue

  • 0

I am a bit confused as to the best way to attach this issue – I have a form that I add to the database but now I would like to upload a image.

The image is ment to go to ./includes/uploads/ and the file name is ment to be inserted into image_path

Controller

class Addsale extends CI_Controller {

function __construct(){
parent::__construct();
}
function index() {
    if(!$this->session->userdata('logged_in')) {
        redirect('admin/home');
    }
    // Set Data
    $data['title'] = "Add Sale";
    $data['sales_pages'] = $this->sales_model->getSalesPages();
    $data['cms_pages'] = $this->navigation_model->getCMSPages();

    //Set File Settings
    $config['upload_path'] = './includes/uploads/';
    $config['allowed_types'] = 'jpg|png';
    $config['max_size'] = '100';
    $config['max_width'] = '1024';
    $config['max_height'] = '768';
    $this->upload->initialize($config);

    //Set Validation
    $this->form_validation->set_rules('name', 'Name', 'trim|required');
    $this->form_validation->set_rules('location', 'Location', 'trim|required');
    $this->form_validation->set_rules('bedrooms', 'Bedrooms', 'trim|is_natural|required');
    $this->form_validation->set_rules('bathrooms', 'Bathrooms', 'trim|required');
    $this->form_validation->set_rules('condition', 'Condition', 'trim|required');
    $this->form_validation->set_rules('description', 'Description', 'trim|required');
    $this->form_validation->set_rules('price', 'Price', 'trim|required');

    if($this->form_validation->run() === TRUE) {

    $data = array(  
        'name' => $this->input->post('name', TRUE),
        'location' => $this->input->post('location', TRUE),
        'bedrooms' => $this->input->post('bedrooms', TRUE),
        'bathrooms' => $this->input->post('bathrooms', TRUE),
        'condition' => $this->input->post('condition', TRUE),
        'description' => $this->input->post('description', TRUE),
        'price' => $this->input->post('price', TRUE),
        'image_path' => $this->input->post('image', TRUE)
        );
        $data = array('image_path' => $this->upload->data());
        $this->sales_model->addSale($data);

        redirect('admin/addsale' , $data);

        $this->session->set_flashdata('success', 'Page Saved');

    }else{
        $data['content'] = $this->load->view('admin/addsale', NULL, TRUE);
        $this->load->view('template', $data);
        }

}


}   

View

<?php
//Setting form attributes
$formAddSale = array('id' => 'addSale', 'name' => 'addSale');
$saleName = array('id' => 'name', 'name' => 'name');
$saleLocation = array('id' => 'location', 'name' => 'location');
$saleBedrooms = array('id' => 'bedrooms','name' => 'bedrooms');
$saleBathrooms = array('id' => 'bathrooms','name' => 'bathrooms');
$saleCondition = array('id' => 'condition','name' => 'condition');
$saleImage = array('id' => 'image', 'name'=> 'image');
$saleDescription = array('id' => 'description','name' => 'description');
$salePrice = array('id' => 'price','name' => 'price');
?>

<section id = "validation"><?php print $this->session->flashdata('success'); ?></section>
<section id = "validation"><?php echo validation_errors();?></section>

<?php
echo form_open_multipart('admin/addsale/', $formAddSale);
echo form_fieldset();
echo form_label('Name:', 'name');
echo form_input($saleName);
echo form_label ('Location', 'location');
echo form_input($saleLocation);
echo form_label ('Bedrooms', 'bedrooms');
echo form_input($saleBedrooms);
echo form_label ('Bathrooms', 'bathrooms');
echo form_input($saleBathrooms);
echo form_label ('Condition', 'condition');
echo form_input($saleCondition);
echo form_label ('Price', 'price');
echo form_input($salePrice);
echo form_label('Image:', 'image');
echo form_upload($saleImage);
echo form_label ('Description', 'description');
echo form_textarea($saleDescription);
echo form_submit('submit','Submit');
echo form_fieldset_close();
echo form_close();
?>

Model

class Sales_model extends CI_Model
  {

function __construct() {
        parent::__construct();
}

function getSalesPages() {

        $query = $this->db->get('sales');
        if($query->num_rows() > 0) return $query->result();

    }

function addSale($data) {

$this->db->insert('sales', $data);
return;
}   

function updateSale($id, $data) {

    $this ->db->where('id', $id);
    $this->db->update('sales', $data);
}
  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T09:47:22+00:00Added an answer on May 21, 2026 at 9:47 am

    I now have this going and this was my final code:

        if($this->form_validation->run() === TRUE) { 
    
    //Set File Settings 
    $config['upload_path'] = './includes/uploads/'; 
    $config['allowed_types'] = 'jpg|png'; 
    $config['max_size'] = '100'; 
    $config['max_width'] = '1024'; 
    $config['max_height'] = '768'; 
    
    $this->load->library('upload', $config); 
    
    $this->upload->do_upload();
    $file_info = $this->upload->data();
    
    $data = array(   
        'name' => $this->input->post('name', TRUE), 
        'location' => $this->input->post('location', TRUE), 
        'bedrooms' => $this->input->post('bedrooms', TRUE), 
        'bathrooms' => $this->input->post('bathrooms', TRUE), 
        'condition' => $this->input->post('condition', TRUE), 
        'description' => $this->input->post('description', TRUE), 
        'price' => $this->input->post('price', TRUE), 
        'image' => $file_info['full_path'] 
        ); 
    $this->sales_model->addSale($data); 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Bit confused here, I have an on-demand instance but do I get charged even
This might be quite simple, but I must say I'm a bit confused on
What's the best way to select only those rows from the table that have
ok, this seems like it should be really simple but Im a bit confused:
Perhaps I'm a bit confused about when to use the waitForPageToLoad command, but what
I'm a bit confused by the Lucene.NET API, but, it may just be a
I am a bit confused at this point on what is an object, what
I'm a bit confused on how to properly select a parent item, that is
I am a bit confused on a certain functionality I would like to implement
I am a bit confused as to the new standards. To the best of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.