0

This is my custom code for creating a node from some arbitrary data - this is executed in the browser from a different website by executing localhost/submit.php - the contents are below:

 <?php

    define('DRUPAL_ROOT', "C:\wamp\www\mydrupalsite");
    require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
    drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

    $bodytext = "Foo bar";

    $node = new stdClass(); 
    $node->type = "article"; 
    node_object_prepare($node);     
    $node->title    = "A new node sees the light of day";
    $node->language = LANGUAGE_NONE; 
    $node->uid = 1;    
    node_save($node);

    ?>

This results in 2 nodes being created even though I've just hit the script once in the browser. Can anyone see what's wrong with this?

The output gives me 2 nodes (both have different nids) and they have identical data.

  • drupal version? – harshal Jan 22 '14 at 8:35
  • fresh install of drupal 7 – Garry Jan 22 '14 at 8:42
  • I tried your code and there is nothing wrong with it. I think there is something wrong in your submit.php. Maybe this code gets triggered twice? – larrydahooster Jan 22 '14 at 8:59
  • that entire code above is my submit.php - I'm pressing enter on it in the browser at localhost/submit.php and then it's getting executed twice (so it seems) - is there any way to debug this? – Garry Jan 22 '14 at 9:04
  • Code looks ok, perhaps something in your drupal install is duplicating the node on save, e.g a node api hook or Rule. Otherwise, the script may be being called twice. In any case, it's odd you're using a standalone script like that, you would be better to use the standard Drupal API and make it a menu callback in a module. – David Thomas Jan 22 '14 at 9:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.