Welcome Guest, Not a member yet? Register   Sign In
Multiple save :(
#1

(This post was last modified: 01-26-2015, 07:35 PM by bobykurniawan.)

Goodday, please check my script first. I'll explain later.

PHP Code:
function detailsave($idshipping NULL)
        {
            
$table 'sidetail';
            
$data = array();            
            foreach(
$_POST['gname'] as $symb => $key)
                {
                    
$data = array('idshipping' => $idshipping,
                                 
 'goodname' => $_POST['gname'][$symb],
                                 
 'nettweight' => $_POST['gnweight'][$symb],
                                 
 'grossweight' => $_POST['ggweight'][$symb],
                                 
 'qty' => $_POST['gqty'][$symb]
                                 
 );
                }
                    
$this->db->insert_batch($table,$data);
    } 
I've been surfing in internet to search about how to fix error in my script. And i found tutorial about insert_batch. Well, i try with that method but still fail.  bunch of warnings appeared when i try the code above
Reply
#2

You have to fill your array properly :

PHP Code:
$data[] = array( .... 

Reply
#3

(This post was last modified: 01-27-2015, 01:59 AM by sv3tli0.)

Lets say you have 3 possible problems..

1st as Rufnex said at the foreach you must store:
PHP Code:
$data[] = array (......); 
.
This way you will have Array of arrays , at the moment you have just 1lvl array which is not valid for multiple inserts...

2nd is that you are using $_POST while CodeIgniter provides you with a $this->input->post method which is secured for manipulating input data..

3rd you must be ready for the case where the post is empty... else you can try to insert empty $data ...
Best VPS Hosting : Digital Ocean
Reply




Theme © iAndrew 2016 - Forum software by © MyBB