Welcome Guest, Not a member yet? Register   Sign In
1st day back
#1

[eluser]tim1965[/eluser]
Sorry in advance, i know i am missing something easy here, but have been struggling all day with this. Long break off over Xmas and newbie, so i will blame it on that.

Problem: i want to get the insert_id value and use this to populate a select statement.
When i echo this i get the correct result. When i try to populate a select i get a unexpected T_VARIABLE on the insert_id line.

thanks in advance

Secondly is my select statement correctly syntax'd ?

// Create user
if ($this->ci->users->create_user($row))
{
$latest_id = $this->ci->db->insert_id();
$query = $this->ci->db->query('SELECT `username` FROM `users` WHERE `id`='$latest_id'');
echo 'test' .$query;

// Trigger event
$this->ci->dx_auth_event->user_activated($this->ci->db->insert_id());

// Delete user from temp
$this->ci->user_temp->delete_user($del);

$result = TRUE;
}

#2

[eluser]Pascal Kriete[/eluser]
It's a quoting issue, you need to use double quotes for the query:
Code:
$query = $this->ci->db->query("SELECT `username` FROM `users` WHERE `id`='$latest_id'");
#3

[eluser]xwero[/eluser]
or do
Code:
$query = $this->ci->db->query('SELECT `username` FROM `users` WHERE `id`='.$latest_id);
This is a monday morning problem Wink
#4

[eluser]tim1965[/eluser]
thanks guys got it in one.




Theme © iAndrew 2016 - Forum software by © MyBB