[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.