Welcome Guest, Not a member yet? Register   Sign In
Having trouble with $this->db->insert_id()
#6

[eluser]Chad Crowell[/eluser]
I found some info on the web that the odbc_insert_id command from PHP doesn't work too well, so I decided not to fight it and went with this, which works fine as this is a low transaction site.

Code:
function add() {
        
        //grab the post
        $kitname = $this->input->post('kitname');
        
        if ($kitname != false) {
            
            //put the kit into the db
            $data = array(
                    'kitname'     => $kitname,
                    'active'    => 0
                    );
                    
            //perform the insert
            $result = $this->db->insert('kits', $data);
            
            if ($result) { //insert was successful
                
                //we need to get that kit id now
                $this->db->select('id')->from('kits')->order_by('id','desc')->limit('1');
                $query = $this->db->get();
                
                if ($query->num_rows() > 0) {
                    
                    $row = $query->row();
                    
                    $kit_id = $row->id;
                    
                    //send the user to the edit form
                    redirect('kits/edit/'.$kit_id, 'refresh');    
                    
                }
                
            }
            
        }
        
    }


Messages In This Thread
Having trouble with $this->db->insert_id() - by El Forum - 03-01-2009, 09:51 PM
Having trouble with $this->db->insert_id() - by El Forum - 03-01-2009, 10:52 PM
Having trouble with $this->db->insert_id() - by El Forum - 03-02-2009, 04:09 AM
Having trouble with $this->db->insert_id() - by El Forum - 03-02-2009, 08:59 AM
Having trouble with $this->db->insert_id() - by El Forum - 03-02-2009, 09:04 AM
Having trouble with $this->db->insert_id() - by El Forum - 03-02-2009, 09:49 AM
Having trouble with $this->db->insert_id() - by El Forum - 04-18-2012, 08:04 PM
Having trouble with $this->db->insert_id() - by El Forum - 04-18-2012, 10:03 PM
Having trouble with $this->db->insert_id() - by El Forum - 04-18-2012, 10:07 PM



Theme © iAndrew 2016 - Forum software by © MyBB