⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Duplicate entries in inserting



Gloriamaris
  • profile picture
  • Member

Posted 24 February 2013 - 19:32 PM

Hi, I have a problem in inserting a new record to the database. Inserting an entry to the database means I should only have one record inserted, right? Instead multiple records show up. Same data but with different id. The most duplicates I have had were 4 copies per insert. :( How do I fix this? Please help me. :\

 

I attached a screenshot of the table.


victor
  • profile picture
  • Member

Posted 24 February 2013 - 20:38 PM

Hi Gloriamaris and welcome to the forum.

Can you explain in more detail how to reproduce the bug.

Show your code.


 


Ryan_T
  • profile picture
  • Member

Posted 21 March 2013 - 04:19 AM

Having the exact same issue. 

 

The table is part of a View page, and whenever I Add Record, it creates 4 entries if using 'Save' button, and 2 records if using 'Save and get back to List' button. 

 

Any input would be greatly appreciated. Thanks. 

 

 

In Controller:

public function view($region='Central')
        {
            $data['trainingRegion'] = $this->training_system->get_list($region);
            
           /* if (empty($data['trainingRegion']))
            {
                show_404();
            }*/
            
            
            $crud = new grocery_CRUD();
            
            $crud->where('region',$region);
            $crud->set_table('training_record');
            
            $crud->columns('first','last','sso','region');
            $crud->fields('first','last','sso','region');
            
            $crud->display_as('first','First Name');
            $crud->display_as('last','Last Name');
            $crud->display_as('sso','SSO');
            $crud->display_as('region','Region');
            
            //$crud->add_fields('first','last','sso','region');
            $crud->edit_fields('first','last','sso','region');
            
            $output = $crud->render();
            $this->_example_output($output);
                   
            /*$this->load->view('templates/header', $data);
            $this->load->view('training/view', $data);
            $this->load->view('templates/footer');*/
        }

        function _example_output($output = null)
        {
            $this->load->view('templates/header', $output);
            $this->load->view('training/view',$output);
            $this->load->view('templates/footer');
        }

 

The front end:

<?php
    foreach($css_files as $file): ?>
<link type="text/css" rel="stylesheet" href="<?php echo $file; ?>" />

<?php endforeach; ?>
<?php foreach($js_files as $file): ?>

<script src="<?php echo $file; ?>"></script>
<?php endforeach; ?>



<div style='height:20px;'></div>
<div>
<?php echo $output; ?>
</div>


victor
  • profile picture
  • Member

Posted 21 March 2013 - 07:08 AM

can you install your project on production hosting? I can test it.

hbs
  • profile picture
  • Member

Posted 27 August 2015 - 07:28 AM

Hi everyone, I have same problem with grocery crud, did anyone get solution?


hbs
  • profile picture
  • Member

Posted 19 September 2015 - 06:59 AM

Somebody has found solution for this refer to this link

 

http://stackoverflow.com/questions/32242834/grocery-crud-insert-duplicate-data-multiple-time

 

Need to edit in datatables-add.js.


egsolis
  • profile picture
  • Member

Posted 15 May 2016 - 03:59 AM

Hi,

I was able to reproduce this bug, but i don't know how to debug it

The doble insert happens when is missing a required field and i click on save, after that comes the error message, i fill the missing field and do save, after that i have to entries in data base

 

my code:

 

 
public function capturarCarta(){ 
        
                                    
                $date = date('Y-m-d');  
                $time = date('H:i:s');
                $this->load->library('ajax_grocery_CRUD');
                $crud = new ajax_grocery_CRUD();
     $crud->set_theme($this->tema);                
     $crud->set_language('spanish');                           
                $crud->set_subject('Carta de Instrucciones');                        
                $crud->where('estatus_estatus_id =',1);                  
     $crud->set_table('carta_instrucciones');    
  $crud->columns('carta_id','ruta_ruta_id', 'fecha',  'tipo_carta_carta_id', 'tipo_carga_tipo_carga_id','numero_contenedor' );                 
                //$crud->add_fields('ruta_ruta_id', 'tipo_carga_tipo_carga_id', 'fecha', 'usuarios_idusuarios', 'tipo_carta_carta_id','clientes_cliente_id','proveedor_proveedor_id','patio_toma','comentarios_patio', 'fecha_posicionamiento','hora_posicionamiento','lugar_posicionamiento_lugar_posicionamiento_id','lugar_entrega','contacto_entrega','fecha_entrega','agente_aduanal','destino_final','booking','naviera_naviera_id', 'custodia', 'comentario_custodia','peso_maximo_permitido_peso_maximo_id');                                 
                $crud->add_fields(  'fecha', 'hora','usuarios_idusuarios', 'tipo_carta_carta_id','clientes_cliente_id','proveedor_proveedor_id','tipo_carga_tipo_carga_id','uni','class','numero_contenedor','comentarios_patio','naviera_naviera_id', 'peso_maximo_permitido_peso_maximo_id','volumen', 'patio_externo', 'booking','contacto_entrega','referencia_cliente','destino_final','lugar_entrega','fecha_posicionamiento','fecha_entrega');                                 


                
              
              
                $this->_set_relation($crud); 
                $this->_display_as($crud);
                $this->_set_rules_edit($crud);                
                $crud->field_type('usuarios_idusuarios', 'hidden', $this->userid);
                $crud->field_type('fecha', 'hidden', $date); 
                 $crud->field_type('hora', 'hidden', $time); 
                $crud->field_type('carta_id', 'readonly'); 
                $crud->field_type('tipo_carta_carta_id', 'hidden', 4);
                $crud->unset_texteditor('comentarios_patio');
                
                $crud->unset_delete();
                $crud->unset_print();
                $crud->unset_list();
                $crud->unset_back_to_list();
                $controller = 'cartamaritima';                
                $function = 'listaAbiertas';
                $parameter = 'usuario';
                $crud->set_lang_string('insert_success_message',
                 'La carta ha sido guardada exitosamente en la base de datos.<br/>Por favor espera a ser reditigido a la lista de Cartas Abiertas.
                 <script type="text/javascript">
                  window.location = "'.site_url($controller.'/'.$function.'/'.$parameter).'";
                 </script>
                 <div style="display:none">
                 '
   );      
                
                try{
$output=$crud->render();
} catch(Exception $e) {


if($e->getCode() == 14) //The 14 is the code of the "You don't have permissions" error on grocery CRUD.
{
redirect(strtolower(__CLASS__).'/'.strtolower(__FUNCTION__).'/add');
}
else
{
show_error($e->getMessage());
}
}
                $data=  [];
                $data['title_value'] = "Abiertas";  
                $data['title_name'] = "Carta de instrucciones "; 
                $data['title_href'] =  "";
                $output->data=$data;                
                $this->_example_output($output);   
    }    




Amit Shah
  • profile picture
  • Member

Posted 15 May 2016 - 15:52 PM

can someone of you facing the issue - share me the screen grab for the network entries...i completely doubt there are multiple entries being generated on the click of the add button - now what can we do in here if thats the case - download and install firefox for developers edition.. and try inspecting the element  (save button) .. you will find all the instances possibly called on the click of that button - if theres something thats repeating .. workarround to remove the same...

 

Hope this insight helps u guys fix the issue

 

Happy GCing :) 


cleberkr
  • profile picture
  • Member

Posted 14 July 2016 - 18:24 PM

I'm having the same problem and i'm trying to fix it right now. If i get to a solution i will post here. If not i will give print screen and show scripts and databases and everything.


cleberkr
  • profile picture
  • Member

Posted 14 July 2016 - 18:26 PM

I'm using this script to test and it has error with no required fields. When i insert it inserts 4 times in database.

 

public function teste_duplicacao()
    {
        $crud = new grocery_CRUD();
        
        $crud->set_table('testes');
        $crud->set_subject('Testes');
 
        $output = $crud->render();   
        $this->_outputView($output);
    }

cleberkr
  • profile picture
  • Member

Posted 14 July 2016 - 18:29 PM

I did not have this error when using old version of grocery crud. This started happening when i updated to this last version 1.5.4


cleberkr
  • profile picture
  • Member

Posted 15 July 2016 - 15:00 PM

Found the error. The error was that i was calling two times the file datatables-add.js . So it was a javascript error and it was my fault. For everyone that are having same error, check the javascripts you are using, probably you are calling them two times.