CodeIgniter Forums
failed to upload image file and save data - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: failed to upload image file and save data (/thread-26620.html)

Pages: 1 2 3 4


failed to upload image file and save data - El Forum - 01-19-2010

[eluser]maria clara[/eluser]
@the prodigy,

i tried what you said,but it don't post still the data i inputted in the fields???
is it in the model??
Code:
function save($data,$item,$details) {
        if ($item == '') {
            $data['link'] = "reports/view";
            $this->db->trans_start();
            $this->db->insert('sec_reports', $data);
            
            $item = $this->db->insert_id();
            $this->save_detail($item,$details);                
            $this->db->trans_complete();
            if ($this->db->affected_rows() == '1')
                {
                    return TRUE;
                }
                
                return FALSE;
        }

this is now my controller looks like.
Code:
$config['upload_path'] = './reports/module/';
                $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())
                        {
                            $file_data = $this->upload->data();
                            //$file_name = $file_data['file_name'];
                            
                        $fields = array(
                                "module_name"=>$this->input->post('module_name'),
                                "slug"=>$this->input->post('slug'),
                                "icon"=>$this->input->post('file_name'),            
                                "report_file_name"=>$this->input->post('report_file_name'),
                                "sql_select"=>$this->input->post('sql_select'),
                                "sql_filter"=>$this->input->post('sql_filter'),
                                "sql_order"=>$this->input->post('sql_order')
                                    );
                            
                        
        
                                /*foreach ($fields as $field)
                                {
                                    if (isset($_POST[$field])) $dt[$field] = $this->input->post($field);
                                }*/
                                //$fields = $this->input->post("fields");
                                $item = $this->input->post("item");
                                $rows = $this->input->post("row0");
                                        
                                $data['item'] = $this->Reports->save($fields,$item,$rows);    
                                
                                $c .= 'Successfully saved item';
                        }    
                        else
                        {
                            
                            $error = array('error' => $this->upload->display_errors());
                            
                            //$this->load->view('at_reports', $error);
                        }
        
                }

                $data['response'] = $c;
                $json['json'] = $data;



failed to upload image file and save data - El Forum - 01-19-2010

[eluser]theprodigy[/eluser]
Quote:$file_data = $this->upload->data();
//$file_name = $file_data['file_name'];

$fields = array(
"module_name"=>$this->input->post('module_name'),
"slug"=>$this->input->post('slug'),
"icon"=>$this->input->post('file_name'),
"report_file_name"=>$this->input->post('report_file_name'),
"sql_select"=>$this->input->post('sql_select'),
"sql_filter"=>$this->input->post('sql_filter'),
"sql_order"=>$this->input->post('sql_order')
);

Notice the difference between your version and mine. (HINT: I have bolded them)

Quote:$file_data = $this->upload->data();
$file_name = $file_data['file_name'];

$fields = array(
"module_name",
"slug",
//"icon"=>$file_data['file_name'],
"icon"=>$file_name,
//'icon' => $file_name,
"report_file_name",
"sql_select",
"sql_filter",
"sql_order"
);

The "icon" DOES NOT RESIDE IN THE POST ARRAY. You CANNOT get it from there. The $this->input->post() function pulls from $_POST.


failed to upload image file and save data - El Forum - 01-19-2010

[eluser]maria clara[/eluser]
i have change it to what you coded..but i haven't seen the result because my connection was not working ryt now.


failed to upload image file and save data - El Forum - 01-19-2010

[eluser]cestaz18[/eluser]
Quote: $file_data = $this->upload->data();
//$file_name = $file_data[‘file_name’];

$fields = array(
“module_name”=>$this->input->post(‘module_name’),
“slug”=>$this->input->post(‘slug’),
“icon”=>$this->input->post(‘file_name’),
“report_file_name”=>$this->input->post(‘report_file_name’),
“sql_select”=>$this->input->post(‘sql_select’),
“sql_filter”=>$this->input->post(‘sql_filter’),
“sql_order”=>$this->input->post(‘sql_order’)
);

Mr. Lab assistant ...

i try your code but i got a data zero ( 0 ) in my icon field...

the rest of my field is ok..the correct data was save correctly...

but in my icon field i got zero ( 0 )value

here's my updated code
CONTROLLER
Code:
$this->upload->do_upload();
$file_data = $this->upload->data();

$fields = array(
                    "module_name"=>$this->input->post('module_name'),
                    "slug"=>$this->input->post('slug'),    
                   "icon"=>$this->input->post('file_name'),          
                    "report_file_name"=>$this->input->post('report_file_name'),
                    "sql_select"=>$this->input->post('sql_select'),
                    "sql_filter"=>$this->input->post('sql_filter'),
                    "sql_order"=>$this->input->post('sql_order')
                    );        

$item = $this->input->post("item");
$rows = $this->input->post("row0");

$data['item'] = $this->Reports->save($fields,$item,$rows);    
$c .= 'Successfully saved item';


MODEL

Code:
function save($data,$item,$details) {
        if ($item == '') {
            $data['link'] = "reports/view";
            $this->db->trans_start();
            $this->db->insert('sec_reports', $data);
            $item = $this->db->insert_id();
            $this->save_detail($item,$details);            
            $this->db->trans_complete();
            }
        else {
            $this->db->trans_start();
            $this->db->where('module_id', $item);
            $this->db->update('sec_reports', $data);
            $this->save_detail($item,$details);                
            $this->db->trans_complete();
        }
        return $item;
    }



failed to upload image file and save data - El Forum - 01-19-2010

[eluser]maria clara[/eluser]
@the prodigy,

hi, it doesn't add anything..i change this:

$item = $this->input->post("item");
$rows = $this->input->post("row0");

$data['item'] = $this->Reports->save($dt,$item,$rows);



to this:

$item = $this->input->post("item");
$rows = $this->input->post("row0");

$data['item'] = $this->Reports->save($fields,$item,$rows);

is there any effect in the model??

MODEL:
Code:
function save($data,$item,$details) {
        if ($item == '') {
            $data['link'] = "reports/view";
            $this->db->trans_start();
            $this->db->insert('sec_reports', $data);
            
            $item = $this->db->insert_id();
            $this->save_detail($item,$details);                
            $this->db->trans_complete();
            if ($this->db->affected_rows() == '1')
                {
                    return TRUE;
                }
                
                return FALSE;
        }
        else {
            $this->db->trans_start();
            $this->db->where('module_id', $item);
            $this->db->update('sec_reports', $data);
            $this->save_detail($item,$details);                
            $this->db->trans_complete();
        }
        return $item;
    }



failed to upload image file and save data - El Forum - 01-19-2010

[eluser]theprodigy[/eluser]
in your controller after you call your save function, run:
Code:
echo $this->db->last_query();

This will output the last query that was ran. This will tell you whether or not your model is running the update or insert query. That will give you an good indication whether you should be looking for new records or possibly a change in a record.

So, your controller should now look like:
Code:
$item = $this->input->post("item");
$rows = $this->input->post("row0");

$data['item'] = $this->Reports->save($fields,$item,$rows);

//Insert it here
echo $this->db->last_query();

$c .= 'Successfully saved item';



failed to upload image file and save data - El Forum - 01-19-2010

[eluser]maria clara[/eluser]
its working a bit now but in the icon field it shows a zero "0", everytime i add an image.
and it shows me this in my console:
Code:
INSERT INTO `erp_sec_reports_parameters` (`report_id`, `parameter_label`, `parameter_name`, `parameter_type`) VALUES (9, 'wer', 'wer', '')



failed to upload image file and save data - El Forum - 01-19-2010

[eluser]cestaz18[/eluser]
[quote author="theprodigy" date="1263974887"]in your controller after you call your save function, run:
Code:
echo $this->db->last_query();

This will output the last query that was ran. This will tell you whether or not your model is running the update or insert query. That will give you an good indication whether you should be looking for new records or possibly a change in a record.

So, your controller should now look like:
Code:
$item = $this->input->post("item");
$rows = $this->input->post("row0");

$data['item'] = $this->Reports->save($fields,$item,$rows);

//Insert it here
echo $this->db->last_query();

$c .= 'Successfully saved item';
[/quote]

Quote:INSERT INTO `erp_sec_reports_parameters` (`report_id`, `parameter_label`, `parameter_name`, `parameter_type`) VALUES (40, 'qr', 'qr', '')<br />
<b>Fatal error</b>: ob_start() [&lt;a href='ref.outcontrol'&gt;ref.outcontrol&lt;/a&gt;]: Cannot use output buffering in output buffering display handlers in <b>C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\comunion\system\libraries\Exceptions.php</b> on line <b>160</b><br />

do you think this is my problem why my insert query not running especially my problem in icon field???


failed to upload image file and save data - El Forum - 01-19-2010

[eluser]theprodigy[/eluser]
ok, it seems like both of you are working on the same exact file. Can we simply this to just one of you, so I'm not getting 2 responses? Thanks.

Ok, there has been some code changes since the beginning, and my brain doesn't seem to want to follow the changes.

Can I please have a new showing of the controller, model, and view, so I can see where we currently stand?


failed to upload image file and save data - El Forum - 01-19-2010

[eluser]maria clara[/eluser]
[quote author="theprodigy" date="1263976420"]ok, it seems like both of you are working on the same exact file. Can we simply this to just one of you, so I'm not getting 2 responses? Thanks.

Ok, there has been some code changes since the beginning, and my brain doesn't seem to want to follow the changes.

Can I please have a new showing of the controller, model, and view, so I can see where we currently stand?[/quote]

sorry for that, thanks you still. Wink