Welcome Guest, Not a member yet? Register   Sign In
how to insert data image from multiple upload form into database( and i have got error)
#1

[eluser]tusukgigi[/eluser]
how to insert data image from multiple upload form into database( and i have got error)

controller :

function create(){
if($this->input->post('submit')){

$config['upload_path'] = './uploads/files';
$config['allowed_types'] = 'gif|png|jpg';
$config['max_size'] = '70';
$config['max_width'] = '500';
$config['max_height'] = '450';
$newname = md5(uniqid(mt_rand()));
$config['file_name'] = $newname;

$this->load->library('upload');
$file = array();
foreach ($_FILES as $key => $row){

$this->upload->initialize($config);
if( !empty($row['name'])){
if(!$this->upload->do_upload($key)){
$data['error'] = $this->upload->display_errors();
$data['title'] = 'Add products';
$data['main'] = 'dashboard/p_jual_create';
$data['districts'] = $this->MPosts->getDistrictsDropDown();
$this->load->vars($data);
$this->load->view('/dashboard/template_admin');
}else{
$file = $this->upload->data();
$createthumbs = true;
$dokfilename = $newname.$file['file_ext'];
$data['upload_data'] = $file;
if($createthumbs){
$dokfile = $file['file_name'];

$config['image_library'] = 'gd2';
$config['source_image'] = 'uploads/files/'.$newname.$file['file_ext'];

$config['new_image'] = "./uploads/files/thumbs/";

$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = FALSE;
$config['thumb_marker'] = "";
$config['width'] = 160;
$config['height'] = 140;

$this->load->library('image_lib', $config);

$this->image_lib->resize();
}
$this->MPosts->addPosts($dokfilename);
$this->session->set_flashdata('message', 'Product created');
redirect('management/index', 'location', 301);

}
}//end !empty($row['name']
} //end foreach
redirect('management/index', 'location', 301);
//} //end if empty

}else{
$data['title'] = 'Add products';
$data['main'] = 'dashboard/p_jual_create';
$data['districts'] = $this->MPosts->getDistrictsDropDown();
$this->load->vars($data);
$this->load->view('/dashboard/template_admin');
}
}


model :


function addPosts($dokfile){
$now = date("Y-m-d H:iConfused");
$randVal = rand(5, 100);
$randCode = $randVal."-".trim(strip_tags($this->input->post('house')));

$data = array(
'kode_rumah' => $randCode
'image1' => $dokfile,
'description' => trim(strip_tags($this->input->post('description')))
);

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

how to insert into database ($dokfile)


who can help me ???
please
#2

[eluser]InsiteFX[/eluser]
Code is incorrect.

Code:
$data = array(
    ‘kode_rumah’ => $randCode
    ‘image1’ => $dokfile,
    ‘description’ => trim(strip_tags($this->input->post(‘description’)))      
  );

Should be:

Code:
$data = array(
    ‘kode_rumah’ => $randCode,
    ‘image1’ => $dokfile,
    ‘description’ => trim(strip_tags($this->input->post(‘description’)))
  );

You forgot the comma after $randCode!

InsiteFX
#3

[eluser]tusukgigi[/eluser]
thank you very much (insiteFX)

but the code is entered only once?.
how to do loops into the database?.

this is my table structure :::


--
-- Table structure for table `products`
--

CREATE TABLE IF NOT EXISTS `products` (
`id` int(255) unsigned NOT NULL auto_increment,
`kode_rumah` varchar(255) NOT NULL,
`image1` varchar(255) NOT NULL,
`image2` varchar(255) NOT NULL,
`image3` varchar(255) NOT NULL,
`description` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

with the code above i only get like this :
--------------------------------------------------------------------------------------------------------
id | kode_rumah | image1 | image2 | image3 | description
1 | 33-ABCDE | 22d55f04e05dc0a3dea1f13527acd237.jpg | | | lorem ipsum dolor sit amet
--------------------------------------------------------------------------------------------------------

how to keep all the fields contain the data ?
#4

[eluser]InsiteFX[/eluser]
Your only passing in one image!

Code:
$data = array(
    ‘kode_rumah’ => $randCode
    ‘image1’ => $dokfile,
    `image2` => $filename,
    `image3` => $filename,
    ‘description’ => trim(strip_tags($this->input->post(‘description’)))      
  );

You need to pass all the image data in $data.

InsiteFX
#5

[eluser]tusukgigi[/eluser]
i try code above and i ve got error ::
-----------------------------------
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: filename

Filename: models/mposts.php

Line Number: 279
-----------------------------------
because i only passing one of image($dokfile)

$this->MPosts->addPosts($dokfilename);

how to fix it?
thank you (InsiteFX)
#6

[eluser]InsiteFX[/eluser]
You need to replace $filename with the filename of your
image2 and image3 files.

This will depend on what images you are saving.

InsiteFX
#7

[eluser]tusukgigi[/eluser]
i try like this

$data = array(
‘kode_rumah’ => $randCode,
‘image1’ => $dokfile,
'image1' => $dokfile,
'image2' => $dokfile['filename'],
'image3' => $dokfile['filename'],
...

in the database just like this

————————————————————————————————————————————————————-------------------------------------
id | kode_rumah | image1 | image2 | image3 | description
1 | 33-ABCDE | 22d55f04e05dc0a3dea1f13527acd237.jpg | 2 | 2 | lorem ipsum dolor sit amet
————————————————————————————————————————————————————--------------------------------------

so, only the front letter in field image2 and image3

help me please




Theme © iAndrew 2016 - Forum software by © MyBB