[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 />
<input type="text" name="naam" id="naam" />
</p>
<p>
<label for="beschrijving">Beschrijving:</label><br />
<input type="text" name="beschrijving" id= "beschrijving" />
</p>
<p>
<label for="ingredienten">Ingredienten:</label><br />
<input type="text" name="ingredienten" id= "ingredienten" />
</p>
<label for="ingredienten">Foto van het gerecht:</label><br />
<input type="file" name="userfile" size="20" />
<br /><br />
<input type="submit" value="upload" />
</form>
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?
Grtz and thanks!