Welcome Guest, Not a member yet? Register   Sign In
Insert help needed!
#2

[eluser]debow[/eluser]
So I've got a little further but not much.

This is what I have so far.
Code:
function AddAthlete($options = array())
    {
        // required values
        if(!$this->_required(
            array('firstname', 'lastname', 'gender'),
            $options)
        ) return false;
        
        $options = $this->_default(array('athStatus' => 'active'), $options); //declares all users active by default
        
        //$this->db->insert('athlete', $options);
        
        //return $this->db->insert_id(); //This will return the id the user was given
        
        if(!$this->db->insert('athlete', $options))
        {
            return FALSE;
        
        }
        echo $this->db->insert_id();  //this shows me the correct athID
        $this->db->affected_rows();
        $last_id = $this->db->insert_id();
        
        
        //The problem is here but not sure why.
        $query = $this->db->query('INSERT INTO eresults (athlete_id,gender,event) SELECT $last_id,athlete.gender,events.event
        FROM athlete,events
        WHERE athlete.athId = $last_id');
        
        
    }

The athlete is added. I can echo the athID by insert_id() and they match. But when assigning $last_id = $this->db->insert_id(); I get the below error when running it.

Code:
A Database Error Occurred

Error Number: 1054

Unknown column '$last_id' in 'field list'

INSERT INTO eresults (athlete_id,gender,event) SELECT $last_id,athlete.gender,events.event FROM athlete,events WHERE athlete.athId = $last_id

Again this works in my normal php project but not sure why it doesn't in CI.


Messages In This Thread
Insert help needed! - by El Forum - 09-28-2010, 11:56 AM
Insert help needed! - by El Forum - 09-28-2010, 01:38 PM
Insert help needed! - by El Forum - 09-28-2010, 01:46 PM
Insert help needed! - by El Forum - 09-28-2010, 02:19 PM



Theme © iAndrew 2016 - Forum software by © MyBB