insert new term as tag on node submit I want to add a term to the the node whenever it is submitted or edited. I have the term id of the term I want to add. 
My first approach of putting this code inside the custom node submit function is not working.

function module_custom_submit_function($form, &amp;$form_state) {
   $nid = $form_state['nid'];
   $node = node_load($nid);
   $term_id = '73';
   $node-&gt;taxonomy[] = $term_id;
   node_save($node);
}


This does not insert the taxonomy term with ID equal to 73.

My second approach was to put query inside the submit function. Though this made changes to the database, the taxonomy terms were not added as tags on the website for the corresponding node.

function module_custom_submit_function($form, &amp;$form_state) {
  $query = db_select('node', 'n');
  $query-&gt;fields('n', array('created', 'sticky'))
   -&gt;condition('nid', $nid, '=');

   $result = $query-&gt;execute();
   foreach ($result as $record) {
     $time = $record-&gt;created;
     $sticky = $record-&gt;sticky;
   }

   db_insert('taxonomy_index')
   -&gt;fields(array('nid' =&gt; $nid, 'tid' =&gt; $term_id, 'sticky' =&gt; $sticky, 'created' =&gt; $time))
   -&gt;execute();
}


Are there any corrections, or alternative ways?

This approach seems to be working for now. I just added this to the submission handler.

   $node = node_load($nid);
   $term_id = '73';
   $node-&gt;field_tags[$node-&gt;language][]['tid'] = $term_id;
   node_save($node);
It looks like you're using code from Drupal 6 in your first example, but from your second you must be using Drupal 7...$node-&gt;taxonomy isn't used in Drupal 7, taxonomy terms are related to entities via fields instead.

Your second example isn't working because the taxonomy_index table is just an index table relating nodes to terms...the hard-link between those two entities is actually contained in the field reference, which you haven't updated.

If I could offer a different approach, it would be to use hook_node_presave(). Using that method you can simply add another term id to the list of selected terms from the form, and rely on the node/field API to commit the changes and update the cache on your behalf.

function MYMODULE_node_presave($node) {
  $term_id = 73;

  // In reality you'd want to loop through the existing field values and check to 
  // avoid duplicates; this is just an example to actually set the value.
  if ($node-&gt;type == 'mytype') {
    $node-&gt;field_term_reference_field_name[$node-&gt;language][] = array('tid' =&gt; $term_id);
  }
}


As an added benefit this will also work for any nodes that you add programatically, not just those added/edited through the node form.