Welcome Guest, Not a member yet? Register   Sign In
upload form with extra information in it
#1

[eluser]Dizza[/eluser]
Hi all,

At the moment i can upload an image and store the path/name to my database. But im stuck with something else. I am trying to add some extra fields to the upload form, like name, description and ingredients.

I did the form oke, but it doesnt seem to upload the data from the fields into the database.

Here is my view, controller and model!

View
Code:
<?php echo form_open_multipart('upload/do_upload');?>
<p>
<label for="naam">Naam:</label><br />
&lt;input type="text" name="naam" id="naam" /&gt;
</p>
<p>
<label for="beschrijving">Beschrijving:</label><br />
&lt;input type="text" name="beschrijving" id=            "beschrijving" /&gt;
</p>
<p>
<label for="ingredienten">Ingredienten:</label><br />
&lt;input type="text" name="ingredienten" id=            "ingredienten" /&gt;
</p>
<label for="ingredienten">Foto van het gerecht:</label><br />
&lt;input type="file" name="userfile" size="20" /&gt;

<br /><br />

&lt;input type="submit" value="upload" /&gt;

&lt;/form&gt;

Controller

Code:
function do_upload()
    {
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']    = '100';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';
        
        $this->load->library('upload', $config);
    
        if ( ! $this->upload->do_upload())
        {
            $error = array('error' => $this->upload->display_errors());
            
            $this->load->view('upload_form', $error);
        }    
        else
        {
            $data = array('upload_data' => $this->upload->data(),
            'naam' => $this->input->post('naam'),
            'beschrijving' => $this->input->post('beschrijving'),
            'ingredienten' => $this->input->post('ingredienten'));
            echo "Het nieuwe gerecht is geupload";
            $img_data = $this->upload->data();
            $file_name = $img_data['file_name'];  
            $this->load->model('upload_model');
            $this->upload_model->save_image($file_name);  
        }


And the model
Code:
function save_image($image_name = '', $data)
    {

$this->db->insert('voorgerecht',Array('naam'=>'naam',
                                              'beschrijving'=>'beschrijving',
                                                'ingredienten'=>'ingredienten',                                                                                            
                                              'afbeelding'=>$image_name                                      
                                              ));
        return;
    }


At the moment i just have some random data to be stored in the database. But i think i need to do something with making variables from the "voorgerecht, beschrijving and afbeelding"

Am i right? Tongue

Grtz and thanks!
#2

[eluser]jpijper[/eluser]
You're not passing $data to save_image?
#3

[eluser]Dizza[/eluser]
[quote author="jpijper" date="1294621980"]You're not passing $data to save_image?[/quote]

Thanks for your feedback!
I now edited this line
Code:
$this->upload_model->save_image($file_name);

to

Code:
$this->upload_model->save_image($file_name, $data);


but it still inserts nothing except the imagename to the database..

thx

EDIT:Already solved it lol, how could i be so stupid! Thanks for the reply jpijper


For the people who need this solution to, its simple:

Controller:
Code:
$data = array('upload_data' => $this->upload->data());
            echo "Het nieuwe gerecht is geupload";
            $img_data = $this->upload->data();
            $file_name = $img_data['file_name'];
            $this->load->model('upload_model');
            $this->upload_model->save_image($file_name);

Model
Code:
function save_image($image_name = '')
    {
        $this->db->insert('voorgerecht',array(    
                                              'naam'     => $this->input->post('naam'),    
                                              'beschrijving'     => $this->input->post('beschrijving'),    
                                              'ingredienten'     => $this->input->post('ingredienten'),            
                                              'afbeelding'=>$image_name                                              
                                              ));




Theme © iAndrew 2016 - Forum software by © MyBB