1

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?

2
  • Are you a drupal fresher? A direct db insert for a node is almost difficult.
    – niksmac
    Commented Apr 18, 2012 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... Commented Apr 18, 2012 at 6:06

1 Answer 1

3

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

<?php
// 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
node_save($newNode);
?>

Best of luck with Drupal.

You will need to refer Creating Drupal 7.x modules

2
  • 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
    Commented Apr 18, 2012 at 13:09
  • @Jimajamma Thanks. +1 for the CCK fields use 'value' thing.
    – niksmac
    Commented Apr 20, 2012 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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