CodeIgniter Forums
1st day back - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: 1st day back (/showthread.php?tid=14330)



1st day back - El Forum - 12-29-2008

[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;
}




1st day back - El Forum - 12-29-2008

[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'");



1st day back - El Forum - 12-29-2008

[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


1st day back - El Forum - 12-29-2008

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