• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
syntax error on insert

#1
[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();

}

#2
[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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.