I am using Drupal 6.25 with Postgres 8.4. I want to create stories from backend. To which tables and columns should I insert values so that one story is shown on my drupal site?

  • Are you a drupal fresher? A direct db insert for a node is almost difficult.
    – niksmac
    Apr 18 '12 at 5:35
  • Yes I am a drupal fresher. My requirement is such that I have one client-server based opensource ERP. From that ERP, on a particular event, I need to put one story based upon data from that ERP. @NikhilMohan Yes I know that's difficult, but you haven't said that's impossible! Can anybody please suggest some way... Apr 18 '12 at 6:06

This is Drupal way to insert a new node from code.

// add node properties
$newNode = (object) NULL;
$newNode->type = '{NODE_TYPE}';
$newNode->title = '{NODE_TITLE}'
$newNode->uid = {USER_ID};
$newNode->created = strtotime("now");
$newNode->changed = strtotime("now");
$newNode->status = 1;
$newNode->comment = 0;
$newNode->promote = 0;
$newNode->moderate = 0;
$newNode->sticky = 0;

// add CCK field data
$newNode->field_{YOUR_CUSTOM_FIELD_1}[0]['value'] = '{DATA_1}';
$newNode->field_{YOUR_CUSTOM_FIELD_2}[0]['value'] = '{DATA_2}';

// save node

Best of luck with Drupal.

You will need to refer Creating Drupal 7.x modules

  • 2
    Couple things, he's using Drupal 6.25 so drupal.org/node/231276 (Creating Drupal 6 Modules) will probably be more helpful that the D7 version, and not all CCK fields use 'value' so be careful there as well as knowing you can have multiple value fields so it's not always indexed to 0 either, but all in all a good start for sure
    – Jimajamma
    Apr 18 '12 at 13:09
  • @Jimajamma Thanks. +1 for the CCK fields use 'value' thing.
    – niksmac
    Apr 20 '12 at 9:22

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.