What is causing this duplicated node issue? I have the following error: When I create a new node from the new data of my external database (inserting a new row in the external database), the new node is duplicated (but it doesn't have type, language, user); this causes the following error:


  Invalid argument supplied for foreach() en /path/web/my_proyect/sites/all/modules/cck/content.module on line 1284.


With my other module, I first extract all the rows of my external database, and convert them in nodes.

I don't know why; I debugged my code, but I don't understand that it is causing the problem.

This is the code of my module.

/* Implement of Hook_cron */
function node_db_extension_cron(){
  inspectAddHoteles();
  drupal_flush_all_caches();
}

function getHotelFromDrupal() {
  $type = '[my_type]';
  $query_nid = "SELECT count(nid) count FROM node WHERE type LIKE '%s'";
  $result_start = db_query($query_nid, $type);
  $cantidad = 0;

  while ($row = db_fetch_object($result_start)) {
      $cantidad = (int) ($row-&gt;count);
  }

  return $cantidad;
}

function getHotelFromExternal() {
  db_set_active('external');

  $result = db_query("SELECT count(id) count FROM [my_table]");
  $cantidad = 0;

  while ($row = db_fetch_object($result)) {
      $cantidad = (int) ($row-&gt;count);
  }

  db_set_active('default');

  return $cantidad;
}

function inspectAddHoteles() {
  global $user;

  $cantd_actual_hotel = getHotelFromDrupal();
  $cantd_final_hotel = getHotelFromExternal();

  /* With the count of nid of drupal and id of db external, i verify if exist new rows  because the count of nid of content and id of rows of my db externa should be equals if don't exists new rows on my db external */

  if ($cantd_actual_hotel &lt; $cantd_final_hotel) {
    db_set_active('external');

    $cant_add = $cantd_final_hotel - $cantd_actual_hotel;
    $query = "SELECT * FROM [my_table] ORDER BY id DESC LIMIT %d";
    $additional = db_query($query, $cant_add);

    db_set_active('default');

    while ($row = db_fetch_object($additional)) {
      $node = new stdClass();
      $node-&gt;uid = $user-&gt;uid;
      $node-&gt;type = 'my_type';
      $node-&gt;title = $row-&gt;title;
      $node-&gt;body = $row-&gt;body;
      $node-&gt;created = time();
      $node-&gt;changed = $node-&gt;created;
      $node-&gt;promote = 0;
      $node-&gt;sticky = 0;
      $node-&gt;format = 2;
      $node-&gt;status = 1; 
      $node-&gt;language = 'es';
      //All field of my content type

      $nodo_1 = node_submit($node);
      node_save($nodo_1);
    }
  }
}
The function node_submit() contains the node_save() function. So you call it twice.