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

[eluser]Chad Crowell[/eluser]
I have a working php/mssql/odbc CI install on 1.7.1. I'm just in the beginnings of a new app.

I've got this function in my controller that inserts a kit title into the db table and *should* return the unique ID from the table and allow me to redirect the user to the edit page for this new kit.

Here is the code:

Code:
function add() {
        
        //grab the post
        $kitname = $this->input->post('kitname');
        
        if ($kitname != false) {
            
            //put the kit into the db
            $data = array(
                    'kitname'     => $kitname
                    );
                    
            //perform the insert
            $this->db->insert('kits', $data);
            //get the new kit ID
            $kit_id = $this->db->insert_id();
            
            if ($kit_id) { //insert was successful
                
                echo $kit_id;

                //send the user to the edit form
                redirect('kits/edit/'.$kit_id, 'refresh');

            }
            
        }
        
    }

The insert is happening with no problems - I can see the new kit every time I test this when I go back to the kit listing page, but I am not seeing a $kit_id echoe'd to the add page and I am not being forwarded to the edit page (I realize I don't need a physical add page but i was using it for testing).

I did have to chase down a couple of bugs for the odbc driver for mssql but its been working great. Maybe related, though?


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