I have Drupal 7 site. I am creating node in my module as follows:-
$newNode = new stdClass();
$newNode->title = "Hello Node";
$newNode->type = "product";
node_object_prepare($newNode); // Sets some defaults.
$newNode->field_prod_type = 1;
$newNode->field_prod_cost = 125.00;
node_submit($newNode); // Prepare node for saving
node_save($newNode);
If I echo the above newNode I do get the successfull created new node id
echo "<pre>; print_r($newNode); exit();
Issue:-
But when I check in the database, I don't see any new record with the above node details.
Any help highly appreciated.
You have to use the node_object_prepare function to prepare the node values, as you have done.
But the node will not be published (status = 1) and have no user attached (uid = 0?). And finally, the format of field are always arrays, with 2 dimensions (language and delta). Then your code must be
Then if you look into your 'node' table, you must have the record for the returned nid. But you cannot have the records in the fields tables ('field_data_field_prod_type' and 'field_data_field_prod_cost') if you don't format it correctly in array...
Do you have any error message when you save your node ?