Welcome Guest, Not a member yet? Register   Sign In
double Insert into database [solved - it was Firefox]
#1

[eluser]xpix[/eluser]
Hi,

Form some reason the data I submit is entered twice into the database. I tried using a model or just simple code but the behavior is the same.

The profiler shows only 1 query and I tried to use a global counter to see how many time the insert function is called. The call happens once

I do not remember having this behavior 2 days ago. What could have change. As far as I know the code is ok.


Trying to insert through Phpmyadmin does not generate a double insert.


Here is my controller
Code:
class AdminSection extends Controller {

    
    function AdminSection()
    {
        parent::Controller();    
        
        if($this->session->userdata('login') != '1') {
            redirect('adminlogin');
        }
        
        $this->output->enable_profiler(TRUE);
        
        $this->css = $this->config->item('jb_admin_css');
        
    }
    
    function index()
    {
        $data['css'] = base_url().$this->css;
        
        $this->load->view('adminheader',$data);
        $this->load->view('adminmenu');
        $this->load->view('adminsection',$data);
        $this->load->view('adminfooter');
    }
    
    // ===============================// !PROGRAMS // ===============================
    
    
    function programs($action = '', $id = ''){
    
        //load model
        $this->load->model('Program');
        
        $data['css'] = base_url().$this->css;
        
        //action
        $data['action'] = $action;
        
        $data['editedProgramName'] = "";
        
        $data['errors'] = "";
        $data['messages'] = "";
        
        //display content - program table
        $data['content'] = "";
        
        //errors for second section
        $data['errors2'] = "";
        $data['messages2'] = "";
        
        
        
        if(!$action){
        
            $data['content'] = $this->Program->list_all();
            
        
        }else if($action == 'edit'){
            
            $data['editedProgram'] = $this->Program->get($id);

            
            $this->form_validation->set_rules('name', 'Name', 'required|trim|xss_clean');
            
            if ($this->form_validation->run() == FALSE){
            
            }else{
            
                $result = $this->Program->update($id, $this->input->post('name'));
                
                if(!$result){
                    $data['errors2'] = "<p>An error has occured!</p>";
                }else{
                    $data['messages2'] = "<p>Success!</p>";
                }
            }
            
            $data['content'] = $this->Program->list_all();
            
            
        }else if($action == 'add'){
            
            $this->form_validation->set_rules('name', 'Name', 'required|trim|xss_clean');
            
            if ($this->form_validation->run() == FALSE){
            
            }else{
            
                $result = $this->Program->add($this->input->post('name'));
                
                if(!$result){
                    $data['errors'] = "<p>An error has occured!</p>";
                }else{
                    $data['messages'] = "<p>Success!</p>";
                }
            }
            
            $data['content'] = $this->Program->list_all();
            
            //clear data
            
            $action = ''; $id = '';
        
        }else if($action == 'delete'){
            
            $result = $this->Program->delete($id);
                
            if(!$result){
                $data['errors2'] = "<p>An error has occured!</p>";
            }else{
                $data['messages2'] = "<p>Success!</p>";
            }
            
            $data['content'] = $this->Program->list_all();
        }
        
        $this->load->view('adminheader',$data);
        $this->load->view('adminmenu');
        $this->load->view('programs',$data);
        $this->load->view('adminfooter');
        
    }

}


Here's the model
Code:
&lt;?php

class Program extends Model {

    var $programs_table = 'jb_programs';
    
    function Program()
    {
        // Call the Model constructor
        parent::Model();
        
    }
    
    function list_all(){
                
        $query = $this->db->get($this->programs_table);
        
        $this->table->set_heading(array('Name', '', ''));
        
        foreach ($query->result() as $row){
            
            $edit = anchor($this->uri->slash_segment(1). $this->uri->slash_segment(2) . 'edit/' . $row->id, 'Edit');
            $delete = anchor($this->uri->slash_segment(1). $this->uri->slash_segment(2). 'delete/' . $row->id, 'Delete');
            
            $this->table->add_row(array($row->name, $edit, $delete));
        }
        
        return $this->table->generate();
        
    }
    
    function add($name){
                
        $data = array('name' => $name);
        
        return $this->db->insert($this->programs_table, $data);
        
    }
    
    function get($id){
    
        $query = $this->db->get_where($this->programs_table, array('id' => $id));
        return $query->row();
        
    }
    
    function update($id,$name){
    
        $data = array('name' => $name);
        $this->db->where('id', $id);
        return $this->db->update($this->programs_table, $data);
    
    }
    
    function delete($id){
    
        $data = array('id' => $id);
        return $this->db->delete($this->programs_table, $data);
    
    }  
    
        
}

?&gt;



Thank you


Messages In This Thread
double Insert into database [solved - it was Firefox] - by El Forum - 05-24-2009, 10:40 AM
double Insert into database [solved - it was Firefox] - by El Forum - 05-24-2009, 11:29 AM
double Insert into database [solved - it was Firefox] - by El Forum - 05-24-2009, 11:39 AM
double Insert into database [solved - it was Firefox] - by El Forum - 05-24-2009, 11:40 AM
double Insert into database [solved - it was Firefox] - by El Forum - 05-24-2009, 11:49 AM
double Insert into database [solved - it was Firefox] - by El Forum - 05-24-2009, 12:02 PM
double Insert into database [solved - it was Firefox] - by El Forum - 05-24-2009, 12:41 PM
double Insert into database [solved - it was Firefox] - by El Forum - 05-24-2009, 12:46 PM



Theme © iAndrew 2016 - Forum software by © MyBB