Unable to save textfield on node_save() $fbuser = new stdClass();
   $fbuser-&gt;first_name = 'abc'; 
   $fbuser-&gt;last_name = 'cde';
   $fbuser-&gt;location = 'Vas';   
   $fbuser-&gt;link = 'http://www.facebook.com'; 
   $fbuser-&gt;gender = 'male';
   module_load_include('inc', 'node', 'node.pages');
   $node = new stdClass();
   $node-&gt;type = 'profile2';
   node_object_prepare($node); 
   $node-&gt;uid = 1;  
   $node-&gt;field_profile_fn[0]['value'] = $fbuser-&gt;first_name;(textfield)  
   $node-&gt;field_profile_ln[0]['value'] = $fbuser-&gt;last_name;(textfield)
   $node-&gt;field_profile_city[0]['value'] = $fbuser-&gt;location;(textfield) 
   $node-&gt;field_profile_facebook[0]['value'] = 'http://www.facebook.com';(textfield) 
   $node-&gt;field_profile_gender[0]['value'] = $fbuser-&gt;gender;(select list) 
   node_save($node);


In the above code I am trying to create a new content of type profile2 .
My node is created but some of the fields show empty text like 

field_profile_facebook which is textfield does not show value provided above and gives empty text.
You forgot to add the language to your fields:

$node-&gt;field_profile_fn[LANGUAGE_NONE][0]['value'] = $fbuser-&gt;first_name;


But even then, this is not the way to go. You should take a look at https://www.drupal.org/documentation/entity-metadata-wrappers

This approach allows you to use something like this:

 $wrapper-&gt;field_profile_fn-&gt;set($fbuser-&gt;first_name);
 $wrapper-&gt;save();