CodeIgniter Forums
syntax error on insert - 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: syntax error on insert (/showthread.php?tid=14431)



syntax error on insert - El Forum - 01-02-2009

[eluser]tim1965[/eluser]
Hi i am trying to parameterise an insert statement from a select that returns an object $row->username. My insert is blowing up with Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING

The problem is something to do with .$row->username. I have checked the insert without this and is correct. So the problem is something to do with my syntax, but its been a long day.
If i remove the . then i get Parse error: syntax error, unexpected T_VARIABLE.

Any help would be much appreciated.





function user_activated($user_id)
{
// Load models
$this->ci->load->model('dx_auth/user_profile', 'user_profile');


// Create user profile
$this->ci->user_profile->create_profile($user_id);

$this->ci->load->model('dx_auth/users', 'users');
$username = $this->ci->users->get_user_by_id($user_id);
$row=$username->row();
$sql = "INSERT INTO master_property_reference (username, property_id, date_time_created, ad_completed) VALUES (".$row->username", NULL, NOW(),'0')";
$this->ci->db->query($sql);
echo $this->ci->db->affected_rows();

}



syntax error on insert - El Forum - 01-02-2009

[eluser]m4rw3r[/eluser]
You're missing a dot after $row->username in the INSERT query.

EDIT: also a good practice is to escape the data before insert